O
Old Monk
Hi all,
Say I have two maps m1 and m2. Both have key as std::string and value
as long.
m1 could hold entries like
"abc" 123
"def" 456
m2 could have entries like
"abc" 789
"hij" 111
I want to show the union of these results like this
"abc" 123 789
"def" 456 0
"hij" 0 111
One way to deal with it would be to form a map<string, vector<long> >,
then loop over m1 and fill it, then loop over m2 and if there is some
existent entry for a key then push_back the value in vector. Doesn't
seem very clean to me. I am sure there might be better approaches. Can
you suggest some ?
Should I have something like map<string, long[2]> instead of m1 and m2
in the first place ?
Thanks.
Say I have two maps m1 and m2. Both have key as std::string and value
as long.
m1 could hold entries like
"abc" 123
"def" 456
m2 could have entries like
"abc" 789
"hij" 111
I want to show the union of these results like this
"abc" 123 789
"def" 456 0
"hij" 0 111
One way to deal with it would be to form a map<string, vector<long> >,
then loop over m1 and fill it, then loop over m2 and if there is some
existent entry for a key then push_back the value in vector. Doesn't
seem very clean to me. I am sure there might be better approaches. Can
you suggest some ?
Should I have something like map<string, long[2]> instead of m1 and m2
in the first place ?
Thanks.