fork(1) download
  1. #include <tr1/unordered_map>
  2. #include <boost/bind.hpp>
  3. #include <boost/lambda/lambda.hpp>
  4. #include <iostream>
  5. #include <algorithm>
  6. struct A {int x; int y; };
  7. int main()
  8. {
  9. typedef std::tr1::unordered_map<int, A> map_t;
  10. map_t m;
  11. A a1 = {1, 100};
  12. m[1] = a1;
  13. A a2 = {10, 101};
  14. m[2] = a2;
  15. A a3 = {-1, 42};
  16. m[1000] = a3;
  17.  
  18. A max_a = max_element(m.begin(), m.end(),
  19. bind(&A::x, bind(&map_t::value_type::second, _1))
  20. < bind(&A::x, bind(&map_t::value_type::second, _2))
  21. )->second;
  22.  
  23. std::cout << "The max A::x was found in {" << max_a.x << ", " << max_a.y << "}\n";
  24.  
  25. }
  26.  
Success #stdin #stdout 0s 2860KB
stdin
Standard input is empty
stdout
The max A::x was found in {10, 101}