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. std::vector<std::string> v { "hello", "world", "czesiek" };
  12. auto result = foo(v, [](std::string const& lhs, std::string const& rhs) -> bool {
  13. return lhs < rhs;
  14. });
  15.  
  16. if(result.second)
  17. std::cout << result.first;
  18.  
  19. return 0;
  20. }
  21.  
  22. template<typename T, typename U>
  23. std::pair<typename T::value_type, bool> foo(T const& v, U const& f)
  24. {
  25. std::set<typename T::value_type, U> s(f);
  26. for(auto const& e : v)
  27. s.insert(e);
  28.  
  29. if(s.size())
  30. return std::make_pair(*std::begin(s), true);
  31. else
  32. return std::make_pair(typename T::value_type(), false);
  33. }
  34.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
czesiek