Serving the Quantitative Finance Community

 
User avatar
JackBryan
Topic Author
Posts: 1
Joined: August 15th, 2010, 6:15 pm

how to iterate a C++ map of map

October 13th, 2011, 4:30 am

I have a map of map std::map< int, std::map > myMap; std::map< int, std::map >::iterator itr;When I try to iterate it : itr = myMap.find(nodeI); // nodeI is int if (itr == myMap.end()) { exit(1) ; } I got error: error: no match for âoperator=â in âitr = ((const PushList*)this)->PushList::myMap.std::map<_Key, _Tp, _Compare, _Alloc>::find [with _Key = int, _Tp = std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std:air<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double> > >, _Compare = std::less<int>, _Alloc = std::allocator<std:air<const int, std::map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std:air<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, double> > > > >](((const int&)((const int*)((int*)nodeI))))âHow can I iterate the map of map ?Any help is really appreciated .thanks
 
User avatar
MattF
Posts: 6
Joined: March 14th, 2003, 7:15 pm

how to iterate a C++ map of map

October 13th, 2011, 7:06 am

Don't you need to specify the datatypes of the inner map?
 
User avatar
DevonFangs
Posts: 0
Joined: November 9th, 2009, 1:49 pm

how to iterate a C++ map of map

October 13th, 2011, 7:32 am

QuoteOriginally posted by: MattFDon't you need to specify the datatypes of the inner map?Yes he does.Jack, pls use "attach code" button next time Also, there might be some overhead in using map of map. Are you sure you can't just use a single map with a little more complicated key instead?
 
User avatar
nosbor
Posts: 0
Joined: December 10th, 2006, 12:54 pm

how to iterate a C++ map of map

October 13th, 2011, 9:28 am

do you need to overload the operator < assuming your types are not the built in ones
 
User avatar
DevonFangs
Posts: 0
Joined: November 9th, 2009, 1:49 pm

how to iterate a C++ map of map

October 13th, 2011, 9:31 am

QuoteOriginally posted by: nosbordo you need to overload the operator < assuming your types are not the built in onesYou need the operator< to be defined for the key type. In this case it's just int, so it's not an issue.
 
User avatar
nosbor
Posts: 0
Joined: December 10th, 2006, 12:54 pm

how to iterate a C++ map of map

October 13th, 2011, 9:43 am

yeah but what are the types of the inner map ?
 
User avatar
DevonFangs
Posts: 0
Joined: November 9th, 2009, 1:49 pm

how to iterate a C++ map of map

October 13th, 2011, 9:51 am

QuoteOriginally posted by: nosboryeah but what are the types of the inner map ?MattF already pointed out that it's the problem. When we hear back from JackBryan we'll figure it out.
 
User avatar
Cuchulainn
Posts: 23029
Joined: July 16th, 2004, 7:38 am

how to iterate a C++ map of map

October 13th, 2011, 2:52 pm

Similar to this idea.
Last edited by Cuchulainn on October 12th, 2011, 10:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 23029
Joined: July 16th, 2004, 7:38 am

how to iterate a C++ map of map

October 13th, 2011, 6:26 pm

 
User avatar
TradesMan
Posts: 0
Joined: January 31st, 2007, 12:53 pm

how to iterate a C++ map of map

October 14th, 2011, 1:16 pm

see this example: