fork download
  1. #include <map>
  2. #include <utility>
  3. #include <iostream>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. namespace {
  10.  
  11. auto pair2params = [](auto&& f)
  12. {
  13. return [f](auto&& p) {
  14. f(p.first, p.second);
  15. };
  16. };
  17.  
  18.  
  19. template<typename Rng, typename Pred>
  20. auto for_each(const Rng& rng, Pred&& pred) -> void
  21. {
  22. for_each(begin(rng), end(rng), pred);
  23. }
  24.  
  25. }
  26.  
  27.  
  28. int main()
  29. {
  30. auto values = map<int, string>{
  31. {0, "hello"},
  32. {1, "world!"}
  33. };
  34.  
  35. for_each(values, pair2params([](int key, const string& value) {
  36. cout << key << ": " << value << "\n";
  37. }));
  38. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
0: hello
1: world!