fork(2) download
  1. #include <iostream>
  2. #include <set>
  3. #include <map>
  4. #include <algorithm>
  5.  
  6. int main()
  7. {
  8. typedef std::map<int, int> M;
  9.  
  10. M m { {1, -1}, {2, -2}, {3, -3}, {4, -4} };
  11.  
  12. auto&& x = std::accumulate(std::begin(m), std::end(m), std::set<int>{},
  13. [](std::set<int>& s, const M::value_type& e) {//std::pair<const int, int>& e) {
  14. return s.insert(e.first), s;
  15. });
  16. for (auto& i : x)
  17. std::cout << i << ' ';
  18. std::cout << '\n';
  19. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
1 2 3 4