fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5.  
  6. template<typename KeyT, typename ValueT>
  7. std::vector<ValueT> mapToVec(const std::map<KeyT, ValueT> &_map)
  8. {
  9. std::vector<ValueT> values;
  10. values.reserve(_map.size());
  11. for(const auto &entry : _map)
  12. {
  13. values.push_back(entry.second);
  14. }
  15. return values;
  16. }
  17.  
  18. int main()
  19. {
  20. std::map<int, std::string> m;
  21. m[1] = "one";
  22. m[2] = "two";
  23. m[3] = "three";
  24.  
  25. auto v = mapToVec(m);
  26. for(const auto &entry : v) {
  27. std::cout << entry << " ";
  28. }
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5532KB
stdin
Standard input is empty
stdout
one two three