Using the initializer_list on a map of vectors

I am trying to initialize the map <ints, vector<ints> > using the new 0X standard, but I cannot understand that the syntax is correct. I would like to make a card with one record with a key: value = 1: <3,4>

 #include <initializer_list> #include <map> #include <vector> using namespace std; map<int, vector<int> > A = {1,{3,4}}; .... 

It dies with the following error using gcc 4.4.3:

error: no matching function for call to std::map<int,std::vector<int,std::allocator<int> >,std::less<int>,std::allocator<std::pair<const int,std::vector<int,std::allocator<int> > > > >::map(<brace-enclosed initializer list>)

Edit

Following Cogwheel's suggestion and adding an extra bracket, it now compiles with a warning that can get rid of the use of the -fno-deduce-init-list flag. Is there any danger?

+6
c ++ c ++ 11 stl
source share
1 answer

As mentioned above, {1,{3,4}} is the only element on the map where the key is 1 and the value is {3,4} . So, you will need { {1,{3,4}} } .

Error simplification:

 error: no matching function for call to map<int,vector<int>>::map(<brace-enclosed initializer list>) 

Not an exact mistake, but nonetheless somewhat useful.

+1
source share

All Articles