I am trying to populate the contents of a C ++ map within a loop area.
#include <set>
#include <map>
map<int, set<int> > maps;
for (int i=0; i<10; i++) {
set<int> seti;
seti.insert(i);
seti.insert(...);
maps.insert ( pair<int,set<int> >(i,seti) );
}
Question: does maps.insert copy the contents of a pair? If the pair instance is invalid after each area of the loop, then such code should fail.
How to properly create the contents of a map (with a pointer and a new instance?) And how to properly clear a map?
thanks for any suggestion about best practices.
--- UPDATE ---
map<int, set<int> >::iterator it;
int k = (*it).first;
set<int> v = (*it).second;
is now "v" also copied from a real instance stored on the map?
if so, then I don’t have the ability to "directly" update the contents of the map.
source
share