"Milind" <ma******@gmail.com> wrote in message
news:11*********************@38g2000cwa.googlegrou ps.com...
: Not very clear. could you kindly point me to where i can get the
: detials..
: insert on msdn, doesn't tell a lot about swap :(
Well, since you removed all context, it doesn't help me reply ;)
Re-quoting:
:: > I trying to use map as: map< typeforkey, set<typeofset> > .
: ...
:: > I intend to do an insert which would look something like:
:: > set<typeofset> myset;
:: > myset.insert(element);
:: >
:: > myHash.insert( std::pair<typeofkey, map<typeofset> > (key, myset));
:: >
:: > now the problem is:
:: > 1. Is there a better way of doing it, interms of explicit creation of
:: > the map Vs the environment creating a temporary for itself??
:: >
:: > 2. If i do insert it like this to the map will be copied to the map,
:: > i.e. all of the elements of the set copied to the new location. i.e.
:: > inside the map?? do i have problems of dangling references?? out of
:: > scope variables?? Can i get a defenetive url or web resource on
this?
::
:: If this was me I would insert my key and a blank set, then get a
: reference
:: to the set in the map and insert into it, just so the set doesn't get
:: copied.
:
: If we are talking about std::map, operator[] pretty much already does
: this, so you can simply write:
:
: myHash[key].swap( myset );
std::map has an operator[]:
Ty& operator[](const Key& keyval);
This function finds an existing map entry where .first==keyval.
If the element does not exist, a new entry is created where
..second is default-constructed.
A reference to the (new or pre-existing) .second member is returned.
You can modify the set provided by reference if appropriate.
If new contents are actually to be substituted, using the
..swap member function (provided by all standard containers)
allows you to exchange the contents of two containers without
any elements being copied.
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form