N
nw
Hi,
I'd like to be able to re-sort a map (a curious aspiration perhaps). I
think basically what I'd like to do is copy one map into another that
uses a different Compare function. I was wondering if there was an
easy way of doing this in general. Or what strategy I could use to do
it?
I've tried something like this:
template<class map1_type,class map2_type>
void copy_map(map1_type &m1,map2_type &m2,int depth) {
if(depth > 0) {
map1_type::const_iterator i = m1.begin();
for(;i != m1.end();++i) {
copy_map(i,m2[i->first],depth-1);
}
} else {
map1_type::const_iterator i = m1.begin();
for(;i != m1.end();++i) {
m2[i->first] = m1[i->first];
}
}
}
But this fails to even compile. Does anyone have any ideas here?
I'd like to be able to re-sort a map (a curious aspiration perhaps). I
think basically what I'd like to do is copy one map into another that
uses a different Compare function. I was wondering if there was an
easy way of doing this in general. Or what strategy I could use to do
it?
I've tried something like this:
template<class map1_type,class map2_type>
void copy_map(map1_type &m1,map2_type &m2,int depth) {
if(depth > 0) {
map1_type::const_iterator i = m1.begin();
for(;i != m1.end();++i) {
copy_map(i,m2[i->first],depth-1);
}
} else {
map1_type::const_iterator i = m1.begin();
for(;i != m1.end();++i) {
m2[i->first] = m1[i->first];
}
}
}
But this fails to even compile. Does anyone have any ideas here?