Re: converting between STL data structures
PaulH <paul.heil@gmail.com> wrote:
I have an STL structure that loooks like this:
std::map<int /*dataC*/, std::map<DWORD /*dataB*/, DWORD /*dataA*/> >
oldRes;
That's just the easiest way I found to save the data based on the way
it's entered.
But, when I want to retrieve the data, I need a structure more like
this:
std::map<DWORD /*dataB*/, std::map<int /*dataC*/, DWORD /*dataA*/> >
newRes;
is there any way of converting from 'oldRes' to 'newRes'?
typedef std::map<DWORD, DWORD> OldMapInner;
typedef std::map<int, OldMapInner> OldMap;
typedef std::map<int, DWORD> NewMapInner;
typedef std::map<DWORD, NewMapInner> NewMap;
OldMap oldRes;
NewMap newRes;
for (OldMap::iterator om = oldRes.begin(); om != oldRes.end(); ++om) {
int dataC = om->first;
OldMapInner& inner = om->second;
for (OldMapInner::iterator omi = inner.begin(); omi != inner.end();
++omi) {
DWORD dataB = omi->first;
DWORD dataA = omi->second;
newRes[dataB][dataC] = dataA;
}
}
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925