fork download
  1. #include <iostream>
  2. #include <functional>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6.  
  7. template<typename T, typename U>
  8. std::pair<typename T::value_type, bool> foo(T const&, U const&);
  9.  
  10. int main() {
  11. typedef std::vector<std::vector<std::string> > vec;
  12. vec v { { "1", "2", "3" }, { "3", "2", "1" } };
  13. for(int i = 0 ; i < 3 ; ++i) {
  14. auto result = foo(v, [&i](vec::value_type const& lhs, vec::value_type const& rhs) -> bool {
  15. return lhs[i] < rhs[i];
  16. });
  17.  
  18. if(result.second)
  19. std::cout << *std::begin(result.first);
  20. }
  21.  
  22. return 0;
  23. }
  24.  
  25. template<typename T, typename U>
  26. std::pair<typename T::value_type, bool> foo(T const& v, U const& f)
  27. {
  28. std::set<typename T::value_type, U> s(f);
  29. for(auto const& e : v)
  30. s.insert(e);
  31.  
  32. if(s.size())
  33. return std::make_pair(*std::begin(s), true);
  34. else
  35. return std::make_pair(typename T::value_type(), false);
  36. }
  37.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
113