fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5.  
  6. struct ClassA {
  7. int val;
  8. ClassA(int v) : val(v) {}
  9. };
  10. bool operator<(const ClassA& lhs, const ClassA& rhs) { return lhs.val < rhs.val; }
  11.  
  12. ClassA key1(1);
  13. ClassA key2(2);
  14. ClassA key3(3);
  15.  
  16. std::map<ClassA, std::vector<std::pair<std::string, std::string>>> stringMap;
  17.  
  18. void functionA()
  19. {
  20. // no point
  21. }
  22.  
  23. void functionB()
  24. {
  25. stringMap[key1].push_back(std::make_pair("foo", "bar"));
  26. stringMap[key1].push_back(std::make_pair("baz", "xyzzy"));
  27. stringMap[key2].push_back(std::make_pair("one", "two"));
  28. stringMap[key3].push_back(std::make_pair("one", "two"));
  29. }
  30.  
  31. void functionC()
  32. {
  33. stringMap.clear();
  34. }
  35.  
  36. int main()
  37. {
  38. functionB();
  39. for(auto& v: stringMap)
  40. {
  41. std::cout << v.first.val << " => {";
  42. for(auto& p: v.second)
  43. std::cout << " '" << p.first << "','" << p.second << "' ";
  44. std::cout << "}\n";
  45. }
  46. functionC();
  47. }
  48.  
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
1 => { 'foo','bar'  'baz','xyzzy' }
2 => { 'one','two' }
3 => { 'one','two' }