fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <memory>
  5. #include <iterator>
  6. #include <algorithm>
  7.  
  8. class Element {};
  9.  
  10. int main()
  11. {
  12. std::map<std::string, std::shared_ptr<Element>> m
  13. {
  14. { "hello", std::make_shared<Element>() },
  15. { "world", std::make_shared<Element>() }
  16. };
  17. std::vector<Element> v;
  18.  
  19. std::transform(m.begin(),
  20. m.end(),
  21. std::back_inserter(v),
  22. [](decltype(*m.begin())& p)
  23. {
  24. return *p.second;
  25. });
  26.  
  27. std::cout << v.size() << "\n";
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
2