diff --git a/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp --- a/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp +++ b/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp @@ -24,6 +24,7 @@ #include #include +#include "MoveOnly.h" #include "test_iterators.h" template @@ -44,26 +45,27 @@ func(in, mid, std::forward(args)...); } -constexpr bool test_all() { - std::array input = {1, 2, 3}; +template +constexpr void run_tests() { + std::array input = {T{1}, T{2}, T{3}}; ProxyRange in{input}; - std::array input2 = {4, 5, 6}; + std::array input2 = {T{4}, T{5}, T{6}}; ProxyRange in2{input2}; auto mid = in.begin() + 1; - std::array output = {4, 5, 6, 7, 8, 9}; + std::array output = {T{4}, T{5}, T{6}, T{7}, T{8}, T{9}}; ProxyIterator out{output.begin()}; //auto out2 = output.begin() + 1; - int num = 2; - Proxy x{num}; + T num{2}; + Proxy x{num}; int count = 1; - auto unary_pred = [](const Proxy& val) { return val.getData() > 0; }; - //auto binary_pred = [](const Proxy& lhs, const Proxy& rhs) { return lhs.getData() == rhs.getData(); }; - auto binary_func = [](const Proxy& lhs, const Proxy&) -> Proxy { return lhs.getData(); }; - //auto gen = [] { return Proxy(42); }; + auto unary_pred = [](const Proxy&) { return true; }; + //auto binary_pred = [](const Proxy&, const Proxy&) { return return false; }; + auto binary_func = [](const Proxy&, const Proxy&) -> Proxy { return Proxy(T()); }; + //auto gen = [] { return Proxy(T{42}); }; //std::mt19937 rand_gen; test(std::ranges::any_of, in, unary_pred); @@ -100,43 +102,51 @@ //test(std::ranges::is_permutation, in, in2); test(std::ranges::for_each, in, std::identity{}); std::ranges::for_each_n(in.begin(), count, std::identity{}); - test(std::ranges::copy, in, out); - std::ranges::copy_n(in.begin(), count, out); - test(std::ranges::copy_if, in, out, unary_pred); - // TODO: uncomment `copy_backward` once https://reviews.llvm.org/D128864 lands. - //test(std::ranges::copy_backward, in, out); + if constexpr (std::copyable) { + test(std::ranges::copy, in, out); + std::ranges::copy_n(in.begin(), count, out); + test(std::ranges::copy_if, in, out, unary_pred); + // TODO: uncomment `copy_backward` once https://reviews.llvm.org/D128864 lands. + //test(std::ranges::copy_backward, in, out); + } test(std::ranges::move, in, out); // TODO: uncomment `move_backward` once https://reviews.llvm.org/D128864 lands. // test(std::ranges::move_backward, in, out); - test(std::ranges::fill, in, x); - std::ranges::fill_n(in.begin(), count, x); - test(std::ranges::transform, in, out, std::identity{}); - test(std::ranges::transform, in, in2, out, binary_func); + if constexpr (std::copyable) { + test(std::ranges::fill, in, x); + std::ranges::fill_n(in.begin(), count, x); + test(std::ranges::transform, in, out, std::identity{}); + test(std::ranges::transform, in, in2, out, binary_func); + } //test(std::ranges::generate, in, gen); //std::ranges::generate_n(in.begin(), count, gen); + if constexpr (std::copyable) { //test(std::ranges::remove_copy, in, out, x); //test(std::ranges::remove_copy_if, in, out, unary_pred); - test(std::ranges::replace, in, x, x); - test(std::ranges::replace_if, in, unary_pred, x); - //test(std::ranges::replace_copy, in, out, x, x); - //test(std::ranges::replace_copy_if, in, out, unary_pred, x); - //test(std::ranges::swap_ranges, in, in2); - test(std::ranges::reverse_copy, in, out); - test_mid(std::ranges::rotate_copy, in, mid, out); - //test(std::ranges::sample, in, out, count, rand_gen); - //test(std::ranges::unique_copy, in, out); - //test(std::ranges::partition_copy, in, out, out2, unary_pred); - //test_mid(std::ranges::partial_sort_copy, in, in2); - test(std::ranges::merge, in, in2, out); - test(std::ranges::set_difference, in, in2, out); - test(std::ranges::set_intersection, in, in2, out); - test(std::ranges::set_symmetric_difference, in, in2, out); - test(std::ranges::set_union, in, in2, out); + test(std::ranges::replace, in, x, x); + test(std::ranges::replace_if, in, unary_pred, x); + //test(std::ranges::replace_copy, in, out, x, x); + //test(std::ranges::replace_copy_if, in, out, unary_pred, x); + } + test(std::ranges::swap_ranges, in, in2); + if constexpr (std::copyable) { + test(std::ranges::reverse_copy, in, out); + test_mid(std::ranges::rotate_copy, in, mid, out); + //test(std::ranges::unique_copy, in, out); + //test(std::ranges::partition_copy, in, out, out2, unary_pred); + //test_mid(std::ranges::partial_sort_copy, in, in2); + test(std::ranges::merge, in, in2, out); + test(std::ranges::set_difference, in, in2, out); + test(std::ranges::set_intersection, in, in2, out); + test(std::ranges::set_symmetric_difference, in, in2, out); + test(std::ranges::set_union, in, in2, out); + } test(std::ranges::remove, in, x); test(std::ranges::remove_if, in, unary_pred); test(std::ranges::reverse, in); //test_mid(std::ranges::rotate, in, mid); //test(std::ranges::shuffle, in, rand_gen); + //test(std::ranges::sample, in, out, count, rand_gen); //test(std::ranges::unique, in); //test(std::ranges::partition, in, binary_pred); //if (!std::is_constant_evaluated()) @@ -158,6 +168,11 @@ // The algorithms that work on uninitialized memory have constraints that prevent proxy iterators from being used with // them. +} + +constexpr bool test_all() { + run_tests(); + run_tests(); return true; } diff --git a/libcxx/test/support/MoveOnly.h b/libcxx/test/support/MoveOnly.h --- a/libcxx/test/support/MoveOnly.h +++ b/libcxx/test/support/MoveOnly.h @@ -43,6 +43,10 @@ friend TEST_CONSTEXPR bool operator>=(const MoveOnly& x, const MoveOnly& y) { return x.data_ >= y.data_; } +#if TEST_STD_VER > 17 + friend constexpr auto operator<=>(const MoveOnly&, const MoveOnly&) = default; +#endif // TEST_STD_VER > 17 + TEST_CONSTEXPR_CXX14 MoveOnly operator+(const MoveOnly& x) const { return MoveOnly(data_ + x.data_); } TEST_CONSTEXPR_CXX14 MoveOnly operator*(const MoveOnly& x) const