unstable_remove_if.cpp 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Range v3 library
  2. //
  3. // Copyright Eric Niebler 2014
  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. //
  10. // Project home: https://github.com/ericniebler/range-v3
  11. #include <range/v3/algorithm/equal.hpp>
  12. #include <range/v3/algorithm/unstable_remove_if.hpp>
  13. #include <range/v3/view/subrange.hpp>
  14. #include "../array.hpp"
  15. #include "../simple_test.hpp"
  16. constexpr bool is_even(int i)
  17. {
  18. return i % 2 == 0;
  19. }
  20. constexpr bool test_constexpr()
  21. {
  22. using IL = std::initializer_list<int>;
  23. test::array<int, 5> arr{{1, 2, 3, 4, 5}};
  24. const auto it = ranges::unstable_remove_if(arr, is_even);
  25. STATIC_CHECK_RETURN(it == arr.begin() + 3);
  26. STATIC_CHECK_RETURN(
  27. ranges::equal(ranges::make_subrange(arr.begin(), it), IL{1, 5, 3}));
  28. return true;
  29. }
  30. int main()
  31. {
  32. STATIC_CHECK(test_constexpr());
  33. return test_result();
  34. }