Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Does a std::set...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 43286 of 48044
Post > Topic >>

Does a std::set ever rebalance ?

by mathieu <mathieu.malaterre@[EMAIL PROTECTED] > Feb 13, 2008 at 08:43 AM

hi there,

  I would like to know if the following piece of code is garantee to
work. I am afraid that the cstring address I am using in the std::map
found from a request in std::set is not garantee to remain the same as
the std::set grows...

thanks
-Mathieu

#include <set>
#include <map>
#include <iostream>

struct FileValuePair {
  const char *filename;
  const char *value;
};

static FileValuePair MAPPINGS[] = {
  { "foo1.dat" , "value1" },
  { "foo2.dat" , "value2" },
  { "foo3.dat" , "value1" },
  { "foo4.dat" , "value3" },
  { "foo5.dat" , "value2" },
  { "foo6.dat" , "value3" },
  { NULL , NULL },
};

int main()
{
  FileValuePair *p = MAPPINGS;
  std::set< std::string > values;
  std::map< const char *, const char * > mappings;
  while(p->filename)
    {
    values.insert( p->value );
    // find back the address:
    const char *v = values.find( p->value )->c_str();
    mappings.insert(
     std::map<const char*,const char*>::value_type(p->filename, v));
    ++p;
    }

  std::map<const char*,const char*>::const_iterator it =
mappings.begin();
  for(; it != mappings.end(); ++it)
    {
    std::cout << it->first << " -> " << it->second << std::endl;
    }

  return 0;
}
 




 4 Posts in Topic:
Does a std::set ever rebalance ?
mathieu <mathieu.malat  2008-02-13 08:43:23 
Re: Does a std::set ever rebalance ?
"Victor Bazarov"  2008-02-13 11:57:02 
Re: Does a std::set ever rebalance ?
Jerry Coffin <jcoffin@  2008-02-17 15:33:05 
Re: Does a std::set ever rebalance ?
Martin York <Martin.Yo  2008-02-17 16:11:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:34:22 CDT 2008.