I try to populate the content of a c++ map within a loop scope.
#include <set>
#include <map>
map<int, set<int> > maps;
for (int i=0; i<10; i++) {
set<int> seti; // content: a set of integers
seti.insert(i);
seti.insert(...);
maps.insert ( pair<int,set<int> >(i,seti) );
}
The question is: does maps.insert copy the pair content? If the pair instance is invalid after each loop scope, then such code should fail.
How should I properly generate map content (with pointer and new the instance?) and how to clean up a map properly?
thanks for any suggestion for best practices.
--- UPDATE ---
map<int, set<int> >::iterator it;
int k = (*it).first;
set<int> v = (*it).second;
is now the 'v' also a copied one from the real instance stored in map?
if yes, than I have no way to 'directly' update the map content.