S
Shailesh Humbad
I have a class and map like this:
class MyObject {
...
};
map<int, MyObject> Box;
Now, I want to reassign the keys of one or more of the pairs in Box
based on another map<int, int> that stores the key assignment like
(old, new). Since MyObject may be big, this should be done without
invoking the MyObject copy constructor. For example, if the map was
like (1 => a, 2 => b, 3 => c), then it might change to (3 => a, 1 =>
b, 2 => c). I know the algorithm, but I'm not very good with STL. If
someone has already worked this out, some sample code would be helpful.
// Create temporary map<int, MyOBject> tempBox
// For each pair in map<Old, New>
// Add <New, Box[Old].MyObject> into tempBox
// Swap the maps
Box.swap(tempBox);
class MyObject {
...
};
map<int, MyObject> Box;
Now, I want to reassign the keys of one or more of the pairs in Box
based on another map<int, int> that stores the key assignment like
(old, new). Since MyObject may be big, this should be done without
invoking the MyObject copy constructor. For example, if the map was
like (1 => a, 2 => b, 3 => c), then it might change to (3 => a, 1 =>
b, 2 => c). I know the algorithm, but I'm not very good with STL. If
someone has already worked this out, some sample code would be helpful.
// Create temporary map<int, MyOBject> tempBox
// For each pair in map<Old, New>
// Add <New, Box[Old].MyObject> into tempBox
// Swap the maps
Box.swap(tempBox);