fork download
  1. #include <map>
  2.  
  3. int main()
  4. {
  5. // Comparison lambda (see https://e...content-available-to-author-only...e.com/w/cpp/container/map/map).
  6. auto comp = [](int a, int b) { return b < a; };
  7.  
  8. // This compiles.
  9. std::map<int, int> m1 {{5, 6}, {3, 4}, {1, 2}};
  10.  
  11. // This also compiles.
  12. std::map<int, int, decltype(comp)> m2(comp);
  13.  
  14. // This doesn't compile (error: expected ‘}’ at end of input).
  15. std::map<int, int, decltype(comp)> m3(comp) {{5, 6}, {3, 4}, {1, 2}};
  16.  
  17. return 0;
  18. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15:49: error: expected ‘,’ or ‘;’ before ‘{’ token
     std::map<int, int, decltype(comp)> m3(comp) {{5, 6}, {3, 4}, {1, 2}};
                                                 ^
prog.cpp:18:1: error: expected ‘}’ at end of input
 }
 ^
stdout
Standard output is empty