fork download
  1. #include <algorithm>
  2. #include <functional>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6. template <class T, typename P = std::less<typename T::value_type>>
  7. void dropsort(T& cont, P pred = P())
  8. {
  9. cont.erase(std::unique(cont.begin(), cont.end(), std::not2(pred)),
  10. cont.end()
  11. );
  12. }
  13.  
  14. int main( )
  15. {
  16. std::vector<int> arr = {0, 2, 1, 4, 3, 6, 5, 7, 9, 8};
  17. dropsort(arr);
  18. std::cout << std::is_sorted(arr.begin(), arr.end());
  19. }
  20.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1