fork download
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. class SomeClass{
  8. public:
  9. SomeClass(size_t value = 0) :
  10. value(value)
  11. {
  12. }
  13. bool operator <(const SomeClass &right)const{
  14. return value < right.value;
  15. }
  16. size_t &data(){
  17. return value;
  18. }
  19. private:
  20. size_t value;
  21.  
  22. };
  23.  
  24.  
  25. int main() {
  26. vector< SomeClass > arr = {3,1,2};
  27. std::sort( begin(arr), end(arr) );
  28. for(auto &elem: arr) {
  29. cout<<elem.data()<<" ";
  30. }
  31. cout<<endl;
  32. std::sort( begin(arr), end(arr), [](auto left, auto right){left=1;return !(left<right);} );
  33. for(auto &elem: arr) {
  34. cout<<elem.data()<<" ";
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1 2 3 
2 3 1