adjacent_remove_if.cpp 1013 B

12345678910111213141516171819202122232425262728293031323334
  1. /// \file
  2. // Range v3 library
  3. //
  4. // Copyright Eric Niebler
  5. // Copyright Christopher Di Bella
  6. //
  7. // Use, modification and distribution is subject to the
  8. // Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. //
  12. // Project home: https://github.com/ericniebler/range-v3
  13. //
  14. #include <range/v3/action/adjacent_remove_if.hpp>
  15. #include "../simple_test.hpp"
  16. #include "../test_utils.hpp"
  17. #include <range/v3/core.hpp>
  18. #include <range/v3/view/iota.hpp>
  19. #include <vector>
  20. int main()
  21. {
  22. using namespace ranges;
  23. auto v = views::ints(1,21) | to<std::vector>();
  24. auto & v2 = actions::adjacent_remove_if(v, [](int x, int y){ return (x + y) % 3 == 0; });
  25. CHECK(std::addressof(v) == std::addressof(v2));
  26. check_equal(v, {2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20});
  27. v |= actions::adjacent_remove_if([](int x, int y){ return (y - x) == 2; });
  28. check_equal(v, {2, 5, 8, 11, 14, 17, 20});
  29. return ::test_result();
  30. }