3

I created a map using

std::map<long,std::vector<long> > indices

When trying to insert a key and vector element with

indices.insert(std::pair<long,std::vector<long> >(0,{0,1,2})); 

I get huge lines of error ending with

C:/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/c++/bits/stl_map.h:685:9: note:   template argument deduction/substitution failed:
Main.cpp:44:66: note:   candidate expects 2 arguments, 1 provided
     indices.insert(std::pair<long,std::vector<long> > (0,{0,1,2}));

if during compilation I do

g++ Main.cpp -std=c++17

However it compiles without any error with

g++ Main.cpp -std=c++11

Is the procedure different in c++17 ? If yes, what is it? Or am I missing something?

GrahamS
  • 9,980
  • 9
  • 49
  • 63
Imanpal Singh
  • 1,105
  • 1
  • 12
  • 22

1 Answers1

0

Your above insert(std::pair<long,std::vector<long> >(0,{0,1,2})) looks fine. It should work if it is GNU C++ 17 I think as it worked in my case.

I think this following would also work now in C++17,

indices.insert({ {0},{{0,1,2}} }); 

C++ 17 has introduced a new overload to permit insert( { {key}, {value, args} } ) syntax.

anatolyg
  • 26,506
  • 9
  • 60
  • 134
FahimAhmed
  • 497
  • 3
  • 14