fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <functional>
  4. #include <iostream>
  5.  
  6. // Fakes a "smart pointer" wrapper around data
  7. template <typename T>
  8. struct Ptr
  9. {
  10. Ptr(T data) : data(data) {};
  11. const T& operator*() const { return data; }
  12.  
  13. private:
  14. T data;
  15. };
  16.  
  17. int main()
  18. {
  19. std::vector<Ptr<double> > vIn;
  20. vIn.push_back(Ptr<double>(5));
  21. vIn.push_back(Ptr<double>(2));
  22. vIn.push_back(Ptr<double>(6));
  23.  
  24. using namespace std::placeholders;
  25. std::sort(
  26. vIn.begin(),
  27. vIn.end(),
  28. std::bind(
  29. std::less<double>(),
  30. std::bind(&Ptr<double>::operator*, _1),
  31. std::bind(&Ptr<double>::operator*, _2)
  32. )
  33. );
  34.  
  35. std::vector<Ptr<double>>::const_iterator it = vIn.begin(), end = vIn.end();
  36. for ( ; it != end; ++it)
  37. std::cout << ',' << **it;
  38. }
Success #stdin #stdout 0s 3020KB
stdin
Standard input is empty
stdout
,2,5,6