remove_if.cpp 927 B

1234567891011121314151617181920212223242526272829303132
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014-present
  4. //
  5. // Use, modification and distribution is subject to the
  6. // Boost Software License, Version 1.0. (See accompanying
  7. // file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #include <vector>
  10. #include <range/v3/core.hpp>
  11. #include <range/v3/view/iota.hpp>
  12. #include <range/v3/algorithm/move.hpp>
  13. #include <range/v3/action/sort.hpp>
  14. #include <range/v3/action/remove_if.hpp>
  15. #include "../simple_test.hpp"
  16. #include "../test_utils.hpp"
  17. int main()
  18. {
  19. using namespace ranges;
  20. auto v = views::ints(1,21) | to<std::vector>();
  21. auto & v2 = actions::remove_if(v, [](int i){return i % 2 == 0;});
  22. CHECK(&v2 == &v);
  23. check_equal(v, {1,3,5,7,9,11,13,15,17,19});
  24. auto && v3 = v | move | actions::remove_if(std::bind(std::less<int>{}, std::placeholders::_1, 10));
  25. check_equal(v3, {11,13,15,17,19});
  26. return ::test_result();
  27. }