fork download
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4.  
  5. template <typename T>
  6. void display(const T& input)
  7. {
  8. for(auto i = input.cbegin(); i!=input.cend(); ++i)
  9. cout << *i << ' ';
  10. cout << endl;
  11. return;
  12. }
  13.  
  14. template <typename R>
  15. class SomeFunc
  16. {
  17. public:
  18. bool operator ()(const R& in1, const R& in2)
  19. {
  20. return in1>in2;
  21. }
  22. };
  23.  
  24. template <typename R>
  25. bool someFunc(const R& in1, const R& in2)
  26. {
  27. return in1<in2;
  28. }
  29.  
  30.  
  31. int main()
  32. {
  33. list<int> myList;
  34. myList.push_back(5);
  35. myList.push_back(137);
  36. myList.push_back(-77);
  37. display(myList);
  38. myList.sort(SomeFunc<decltype(myList)::value_type>());
  39. display(myList);
  40. myList.sort(someFunc<decltype(myList)::value_type>);
  41. display(myList);
  42.  
  43. cin.ignore();
  44. return 0;
  45.  
  46. };
Success #stdin #stdout 0s 3036KB
stdin
Standard input is empty
stdout
5 137 -77 
137 5 -77 
-77 5 137