fork(5) download
  1. #include <initializer_list>
  2. #include <iostream>
  3. #include <map>
  4. #include <string>
  5. #include <utility>
  6.  
  7.  
  8. struct Typer
  9. {
  10. std::string data;
  11.  
  12. Typer(const char *s) : data(s) {}
  13. };
  14.  
  15.  
  16. struct MyClass
  17. {
  18. MyClass(std::initializer_list<std::pair<std::string, Typer>> i)
  19. : myMap(begin(i), end(i))
  20. {}
  21.  
  22. std::map<std::string, Typer> myMap;
  23. };
  24.  
  25. int main()
  26. {
  27. MyClass m = {
  28. {"foo", "bar"},
  29. {"biz", "buz"},
  30. {"bez", "boz"}
  31. };
  32. for (auto&& p: m.myMap)
  33. std::cout << p.first << " - " << p.second.data << '\n';
  34. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
bez - boz
biz - buz
foo - bar