diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp index 1ca397c92a334..3d4ee23a5a7ff 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy.pass.cpp @@ -18,6 +18,7 @@ #include "test_macros.h" #include "test_iterators.h" +#include "type_algorithms.h" class PaddedBase { public: @@ -81,7 +82,7 @@ TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) { } TEST_CONSTEXPR_CXX20 bool test() { - types::for_each(types::cpp17_input_iterator_list(), TestInIters()); + types::for_each(types::cpp17_input_iterator_list(), TestInIters()); { // Make sure that padding bits aren't copied Derived src(1, 2, 3); @@ -91,7 +92,6 @@ TEST_CONSTEXPR_CXX20 bool test() { assert(dst.b_ == 2); assert(dst.c_ == 6); } - { // Make sure that overlapping ranges can be copied int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::copy(a + 3, a + 10, a); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp index 445c7718e1111..8a528a96f5294 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_backward.pass.cpp @@ -19,6 +19,7 @@ #include "test_macros.h" #include "test_iterators.h" +#include "type_algorithms.h" #include "user_defined_integral.h" class PaddedBase { @@ -36,21 +37,29 @@ class Derived : public PaddedBase { std::int8_t c_; }; -template -TEST_CONSTEXPR_CXX20 void test_copy_backward() { - { - const unsigned N = 1000; - int ia[N] = {}; - for (unsigned i = 0; i < N; ++i) - ia[i] = i; - int ib[N] = {0}; - - OutIter r = std::copy_backward(InIter(ia), InIter(ia + N), OutIter(ib + N)); - assert(base(r) == ib); - for (unsigned i = 0; i < N; ++i) - assert(ia[i] == ib[i]); +struct TestIterators { + template + TEST_CONSTEXPR_CXX20 void operator()() { + types::for_each(types::bidirectional_iterator_list(), TestImpl()); } -} + + template + struct TestImpl { + template + TEST_CONSTEXPR_CXX20 void operator()() { + const unsigned N = 1000; + int ia[N] = {}; + for (unsigned i = 0; i < N; ++i) + ia[i] = i; + int ib[N] = {0}; + + OutIter r = std::copy_backward(InIter(ia), InIter(ia + N), OutIter(ib + N)); + assert(base(r) == ib); + for (unsigned i = 0; i < N; ++i) + assert(ia[i] == ib[i]); + } + }; +}; TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) { std::vector in(N, false); @@ -70,31 +79,10 @@ TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) { } return true; -}; +} TEST_CONSTEXPR_CXX20 bool test() { - test_copy_backward, bidirectional_iterator >(); - test_copy_backward, random_access_iterator >(); - test_copy_backward, int*>(); - - test_copy_backward, bidirectional_iterator >(); - test_copy_backward, random_access_iterator >(); - test_copy_backward, int*>(); - - test_copy_backward >(); - test_copy_backward >(); - test_copy_backward(); - -#if TEST_STD_VER > 17 - test_copy_backward, bidirectional_iterator>(); - test_copy_backward, random_access_iterator>(); - test_copy_backward, int*>(); - - test_copy_backward, contiguous_iterator>(); - test_copy_backward, contiguous_iterator>(); - test_copy_backward, contiguous_iterator>(); - test_copy_backward>(); -#endif + types::for_each(types::bidirectional_iterator_list(), TestIterators()); { // Make sure that padding bits aren't copied Derived src(1, 2, 3); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp index 57214e65455b4..3bee77738e342 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_if.pass.cpp @@ -19,75 +19,48 @@ #include "test_macros.h" #include "test_iterators.h" +#include "type_algorithms.h" -struct Pred -{ - TEST_CONSTEXPR_CXX14 bool operator()(int i) {return i % 3 == 0;} +struct Pred { + TEST_CONSTEXPR_CXX14 bool operator()(int i) { return i % 3 == 0; } }; -template -TEST_CONSTEXPR_CXX20 void -test_copy_if() -{ +template +struct TestOutIters { + template + TEST_CONSTEXPR_CXX20 void operator()() { const unsigned N = 1000; - int ia[N] = {}; + int ia[N] = {}; for (unsigned i = 0; i < N; ++i) - ia[i] = i; + ia[i] = i; int ib[N] = {0}; - OutIter r = std::copy_if(InIter(ia), InIter(ia+N), OutIter(ib), Pred()); - assert(base(r) == ib+N/3+1); - for (unsigned i = 0; i < N/3+1; ++i) - assert(ib[i] % 3 == 0); -} - -TEST_CONSTEXPR_CXX20 bool -test() -{ - test_copy_if, cpp17_output_iterator >(); - test_copy_if, cpp17_input_iterator >(); - test_copy_if, forward_iterator >(); - test_copy_if, bidirectional_iterator >(); - test_copy_if, random_access_iterator >(); - test_copy_if, int*>(); - - test_copy_if, cpp17_output_iterator >(); - test_copy_if, cpp17_input_iterator >(); - test_copy_if, forward_iterator >(); - test_copy_if, bidirectional_iterator >(); - test_copy_if, random_access_iterator >(); - test_copy_if, int*>(); - - test_copy_if, cpp17_output_iterator >(); - test_copy_if, cpp17_input_iterator >(); - test_copy_if, forward_iterator >(); - test_copy_if, bidirectional_iterator >(); - test_copy_if, random_access_iterator >(); - test_copy_if, int*>(); - - test_copy_if, cpp17_output_iterator >(); - test_copy_if, cpp17_input_iterator >(); - test_copy_if, forward_iterator >(); - test_copy_if, bidirectional_iterator >(); - test_copy_if, random_access_iterator >(); - test_copy_if, int*>(); + OutIter r = std::copy_if(InIter(ia), InIter(ia + N), OutIter(ib), Pred()); + assert(base(r) == ib + N / 3 + 1); + for (unsigned i = 0; i < N / 3 + 1; ++i) + assert(ib[i] % 3 == 0); + } +}; - test_copy_if >(); - test_copy_if >(); - test_copy_if >(); - test_copy_if >(); - test_copy_if >(); - test_copy_if(); +struct TestInIters { + template + TEST_CONSTEXPR_CXX20 void operator()() { + types::for_each( + types::concatenate_t, types::type_list > >(), + TestOutIters()); + } +}; +TEST_CONSTEXPR_CXX20 bool test() { + types::for_each(types::cpp17_input_iterator_list(), TestInIters()); return true; } -int main(int, char**) -{ - test(); +int main(int, char**) { + test(); #if TEST_STD_VER > 17 - static_assert(test()); + static_assert(test()); #endif return 0; diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp index 889e71f4eceb9..2053134a01a2f 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/copy_n.pass.cpp @@ -18,6 +18,7 @@ #include "test_macros.h" #include "test_iterators.h" +#include "type_algorithms.h" #include "user_defined_integral.h" typedef UserDefinedIntegral UDI; @@ -37,37 +38,31 @@ class Derived : public PaddedBase { std::int8_t c_; }; -template -TEST_CONSTEXPR_CXX20 void test_copy_n() { - { - const unsigned N = 1000; - int ia[N] = {}; - for (unsigned i = 0; i < N; ++i) - ia[i] = i; - int ib[N] = {0}; - - OutIter r = std::copy_n(InIter(ia), UDI(N / 2), OutIter(ib)); - assert(base(r) == ib + N / 2); - for (unsigned i = 0; i < N / 2; ++i) - assert(ia[i] == ib[i]); +struct TestIterators { + template + TEST_CONSTEXPR_CXX20 void operator()() { + types::for_each( + types::concatenate_t, types::type_list > >(), + TestImpl()); } - { // Make sure that padding bits aren't copied - Derived src(1, 2, 3); - Derived dst(4, 5, 6); - std::copy_n(static_cast(&src), 1, static_cast(&dst)); - assert(dst.a_ == 1); - assert(dst.b_ == 2); - assert(dst.c_ == 6); - } - - { // Make sure that overlapping ranges can be copied - int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - std::copy_n(a + 3, 7, a); - int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10}; - assert(std::equal(a, a + 10, expected)); - } -} + template + struct TestImpl { + template + TEST_CONSTEXPR_CXX20 void operator()() { + const unsigned N = 1000; + int ia[N] = {}; + for (unsigned i = 0; i < N; ++i) + ia[i] = i; + int ib[N] = {0}; + + OutIter r = std::copy_n(InIter(ia), UDI(N / 2), OutIter(ib)); + assert(base(r) == ib + N / 2); + for (unsigned i = 0; i < N / 2; ++i) + assert(ia[i] == ib[i]); + } + }; +}; TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) { std::vector in(N, false); @@ -90,40 +85,23 @@ TEST_CONSTEXPR_CXX20 bool test_vector_bool(std::size_t N) { } TEST_CONSTEXPR_CXX20 bool test() { - test_copy_n, cpp17_output_iterator >(); - test_copy_n, cpp17_input_iterator >(); - test_copy_n, forward_iterator >(); - test_copy_n, bidirectional_iterator >(); - test_copy_n, random_access_iterator >(); - test_copy_n, int*>(); - - test_copy_n, cpp17_output_iterator >(); - test_copy_n, cpp17_input_iterator >(); - test_copy_n, forward_iterator >(); - test_copy_n, bidirectional_iterator >(); - test_copy_n, random_access_iterator >(); - test_copy_n, int*>(); - - test_copy_n, cpp17_output_iterator >(); - test_copy_n, cpp17_input_iterator >(); - test_copy_n, forward_iterator >(); - test_copy_n, bidirectional_iterator >(); - test_copy_n, random_access_iterator >(); - test_copy_n, int*>(); - - test_copy_n, cpp17_output_iterator >(); - test_copy_n, cpp17_input_iterator >(); - test_copy_n, forward_iterator >(); - test_copy_n, bidirectional_iterator >(); - test_copy_n, random_access_iterator >(); - test_copy_n, int*>(); - - test_copy_n >(); - test_copy_n >(); - test_copy_n >(); - test_copy_n >(); - test_copy_n >(); - test_copy_n(); + types::for_each(types::cpp17_input_iterator_list(), TestIterators()); + + { // Make sure that padding bits aren't copied + Derived src(1, 2, 3); + Derived dst(4, 5, 6); + std::copy_n(static_cast(&src), 1, static_cast(&dst)); + assert(dst.a_ == 1); + assert(dst.b_ == 2); + assert(dst.c_ == 6); + } + + { // Make sure that overlapping ranges can be copied + int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + std::copy_n(a + 3, 7, a); + int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10}; + assert(std::equal(a, a + 10, expected)); + } { // Test vector::iterator optimization assert(test_vector_bool(8)); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy.pass.cpp index bee1ef9bcec33..6229aac733a9c 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy.pass.cpp @@ -23,6 +23,7 @@ #include "test_macros.h" #include "test_execution_policies.h" #include "test_iterators.h" +#include "type_algorithms.h" EXECUTION_POLICY_SFINAE_TEST(copy); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy_n.pass.cpp index 128108ac13811..7208be75c70d0 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy_n.pass.cpp @@ -23,6 +23,7 @@ #include "test_macros.h" #include "test_execution_policies.h" #include "test_iterators.h" +#include "type_algorithms.h" EXECUTION_POLICY_SFINAE_TEST(copy_n); @@ -58,7 +59,7 @@ struct TestIteratorsInt { }; struct CopiedToTester { - bool copied_to = false; + bool copied_to = false; CopiedToTester() = default; CopiedToTester(const CopiedToTester&) {} CopiedToTester& operator=(const CopiedToTester&) { diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy_n.pass.cpp index c7031f63a02f6..577328d663d9f 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/ranges.copy_n.pass.cpp @@ -40,7 +40,7 @@ static_assert(!HasCopyNIt, std::ranges::in_out_result>); -template +template constexpr void test_iterators() { { // simple test std::array in{1, 2, 3, 4}; @@ -61,26 +61,6 @@ constexpr void test_iterators() { } } -template -constexpr void test_in_iterators() { - test_iterators, Out, sentinel_wrapper>>(); - test_iterators, Out>(); - test_iterators, Out>(); - test_iterators, Out>(); - test_iterators, Out>(); -} - -template -constexpr void test_proxy_in_iterators() { - test_iterators>, - Out, - sentinel_wrapper>>>(); - test_iterators>, Out>(); - test_iterators>, Out>(); - test_iterators>, Out>(); - test_iterators>, Out>(); -} - #if TEST_STD_VER >= 23 constexpr bool test_vector_bool(std::size_t N) { std::vector in(N, false); @@ -104,17 +84,12 @@ constexpr bool test_vector_bool(std::size_t N) { #endif constexpr bool test() { - test_in_iterators>(); - test_in_iterators>(); - test_in_iterators>(); - test_in_iterators>(); - test_in_iterators>(); - - test_proxy_in_iterators>>(); - test_proxy_in_iterators>>(); - test_proxy_in_iterators>>(); - test_proxy_in_iterators>>(); - test_proxy_in_iterators>>(); + types::for_each(types::cpp20_input_iterator_list{}, []() { + types::for_each(types::cpp20_input_iterator_list{}, []() { + test_iterators(); + test_iterators, ProxyIterator>(); + }); + }); { // check that every element is copied exactly once struct CopyOnce { diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp index 7656be73c14c6..0e532ae834e7f 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp @@ -22,6 +22,7 @@ #include "sized_allocator.h" #include "test_macros.h" #include "test_iterators.h" +#include "type_algorithms.h" template TEST_CONSTEXPR_CXX20 void diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp index 3b67101a8b29e..98c412fb6cdc0 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp @@ -14,108 +14,93 @@ // fill_n(Iter first, Size n, const T& value); #include +#include #include +#include #include #include "sized_allocator.h" #include "test_macros.h" #include "test_iterators.h" +#include "type_algorithms.h" #include "user_defined_integral.h" -#if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { - const std::size_t N = 5; - int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N - - auto it = std::fill_n(std::begin(ib), N, 5); - return it == (std::begin(ib) + N) && std::all_of(std::begin(ib), it, [](int a) { return a == 5; }) && - *it == 0 // don't overwrite the last value in the output array - ; -} -#endif - typedef UserDefinedIntegral UDI; -template -void test_char() { - char a[4] = {}; - Iter it = std::fill_n(Iter(a), UDI(4), char(1)); - assert(base(it) == a + 4); - assert(a[0] == 1); - assert(a[1] == 1); - assert(a[2] == 1); - assert(a[3] == 1); +template +TEST_CONSTEXPR_CXX20 void +test(Container in, size_t from, size_t n, typename Container::value_type value, Container expected) { + Iter it = std::fill_n(Iter(in.data() + from), UDI(n), value); + assert(base(it) == in.data() + from + n); + assert(in == expected); } -template -void test_int() { - int a[4] = {}; - Iter it = std::fill_n(Iter(a), UDI(4), 1); - assert(base(it) == a + 4); - assert(a[0] == 1); - assert(a[1] == 1); - assert(a[2] == 1); - assert(a[3] == 1); -} +template +struct Test { + template + TEST_CONSTEXPR_CXX20 void operator()() { + { + std::array in = {1, 2, 3, 4}; + std::array expected = {5, 5, 5, 5}; + test(in, 0, 4, 5, expected); + } + { + std::array in = {1, 2, 3, 4}; + std::array expected = {1, 5, 5, 4}; + test(in, 1, 2, 5, expected); + } + } +}; -void test_int_array() { - int a[4] = {}; - assert(std::fill_n(a, UDI(4), static_cast(1)) == a + 4); - assert(a[0] == 1); - assert(a[1] == 1); - assert(a[2] == 1); - assert(a[3] == 1); +TEST_CONSTEXPR_CXX20 void test_int_array() { + { + int a[4] = {}; + assert(std::fill_n(a, UDI(4), static_cast(1)) == a + 4); + assert(a[0] == 1 && a[1] == 1 && a[2] == 1 && a[3] == 1); + } +#if TEST_STD_VER >= 11 + { + const std::size_t N = 5; + int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N + + auto it = std::fill_n(std::begin(ib), N, 5); + assert(it == (std::begin(ib) + N) && std::all_of(std::begin(ib), it, [](int a) { return a == 5; }) && + *it == 0 // don't overwrite the last value in the output array + ); + } +#endif } struct source { - source() : i(0) {} - - operator int() const { return i++; } - mutable int i; + TEST_CONSTEXPR source() = default; + TEST_CONSTEXPR_CXX20 operator int() const { return 1; } }; -void test_int_array_struct_source() { +TEST_CONSTEXPR_CXX20 void test_int_array_struct_source() { int a[4] = {}; assert(std::fill_n(a, UDI(4), source()) == a + 4); - assert(a[0] == 0); + assert(a[0] == 1); assert(a[1] == 1); - assert(a[2] == 2); - assert(a[3] == 3); -} - -struct test1 { - test1() : c(0) {} - test1(char xc) : c(xc + 1) {} - char c; -}; - -void test_struct_array() { - test1 test1a[4] = {}; - assert(std::fill_n(test1a, UDI(4), static_cast(10)) == test1a + 4); - assert(test1a[0].c == 11); - assert(test1a[1].c == 11); - assert(test1a[2].c == 11); - assert(test1a[3].c == 11); + assert(a[2] == 1); + assert(a[3] == 1); } class A { char a_; public: - A() {} - explicit A(char a) : a_(a) {} - operator unsigned char() const { return 'b'; } + TEST_CONSTEXPR A() : a_('a') {}; + TEST_CONSTEXPR explicit A(char a) : a_(a) {} + TEST_CONSTEXPR operator unsigned char() const { return 'b'; } - friend bool operator==(const A& x, const A& y) { return x.a_ == y.a_; } + TEST_CONSTEXPR friend bool operator==(const A& x, const A& y) { return x.a_ == y.a_; } }; -void test5() { - A a[3]; - assert(std::fill_n(&a[0], UDI(3), A('a')) == a + 3); - assert(a[0] == A('a')); - assert(a[1] == A('a')); - assert(a[2] == A('a')); -} +struct B { + TEST_CONSTEXPR B() : c(0) {} + TEST_CONSTEXPR B(char xc) : c(xc + 1) {} + char c; +}; struct Storage { union { @@ -124,11 +109,6 @@ struct Storage { }; }; -void test6() { - Storage foo[5]; - std::fill_n(&foo[0], UDI(5), Storage()); -} - // Make sure std::fill_n behaves properly with std::vector iterators with custom size types. // See https://github.com/llvm/llvm-project/pull/122410. TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() { @@ -162,30 +142,44 @@ TEST_CONSTEXPR_CXX20 void test_bititer_with_custom_sized_types() { } } -int main(int, char**) { - test_char >(); - test_char >(); - test_char >(); - test_char >(); - test_char(); - - test_int >(); - test_int >(); - test_int >(); - test_int >(); - test_int(); +TEST_CONSTEXPR_CXX20 void test_struct_array() { + { + A a[3]; + assert(std::fill_n(&a[0], UDI(3), A('a')) == a + 3); + assert(a[0] == A('a')); + assert(a[1] == A('a')); + assert(a[2] == A('a')); + } + { + B b[4] = {}; + assert(std::fill_n(b, UDI(4), static_cast(10)) == b + 4); + assert(b[0].c == 11); + assert(b[1].c == 11); + assert(b[2].c == 11); + assert(b[3].c == 11); + } + { + Storage foo[5]; + std::fill_n(&foo[0], UDI(5), Storage()); + } +} + +TEST_CONSTEXPR_CXX20 bool test() { + types::for_each(types::forward_iterator_list(), Test()); + types::for_each(types::forward_iterator_list(), Test()); test_int_array(); - test_int_array_struct_source(); test_struct_array(); - - test5(); - test6(); - + test_int_array_struct_source(); test_bititer_with_custom_sized_types(); -#if TEST_STD_VER > 17 - static_assert(test_constexpr()); + return true; +} + +int main(int, char**) { + test(); +#if TEST_STD_VER >= 20 + static_assert(test()); #endif return 0; diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill.pass.cpp index 556326fb0894c..e456fa8986aad 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill.pass.cpp @@ -23,6 +23,7 @@ #include "test_macros.h" #include "test_execution_policies.h" #include "test_iterators.h" +#include "type_algorithms.h" EXECUTION_POLICY_SFINAE_TEST(fill); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill_n.pass.cpp index 4abbd6f7a17c3..51232dfef1606 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill_n.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill_n.pass.cpp @@ -23,6 +23,7 @@ #include "test_macros.h" #include "test_execution_policies.h" #include "test_iterators.h" +#include "type_algorithms.h" EXECUTION_POLICY_SFINAE_TEST(fill_n); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp index b1ad6873bc5e5..5324a327b50bc 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move.pass.cpp @@ -24,6 +24,7 @@ #include "MoveOnly.h" #include "test_iterators.h" #include "test_macros.h" +#include "type_algorithms.h" class PaddedBase { public: @@ -45,15 +46,15 @@ struct Test { template TEST_CONSTEXPR_CXX20 void operator()() { const unsigned N = 1000; - int ia[N] = {}; + int ia[N] = {}; for (unsigned i = 0; i < N; ++i) - ia[i] = i; + ia[i] = i; int ib[N] = {0}; - OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib)); - assert(base(r) == ib+N); + OutIter r = std::move(InIter(ia), InIter(ia + N), OutIter(ib)); + assert(base(r) == ib + N); for (unsigned i = 0; i < N; ++i) - assert(ia[i] == ib[i]); + assert(ia[i] == ib[i]); } }; @@ -73,13 +74,13 @@ struct Test1 { const unsigned N = 100; std::unique_ptr ia[N]; for (unsigned i = 0; i < N; ++i) - ia[i].reset(new int(i)); + ia[i].reset(new int(i)); std::unique_ptr ib[N]; - OutIter r = std::move(InIter(ia), InIter(ia+N), OutIter(ib)); - assert(base(r) == ib+N); + OutIter r = std::move(InIter(ia), InIter(ia + N), OutIter(ib)); + assert(base(r) == ib + N); for (unsigned i = 0; i < N; ++i) - assert(*ib[i] == static_cast(i)); + assert(*ib[i] == static_cast(i)); } }; @@ -96,7 +97,6 @@ TEST_CONSTEXPR_CXX20 bool test() { types::for_each(types::cpp17_input_iterator_list(), TestOutIters()); if (TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED) types::for_each(types::cpp17_input_iterator_list*>(), Test1OutIters()); - { // Make sure that padding bits aren't copied Derived src(1, 2, 3); Derived dst(4, 5, 6); @@ -105,20 +105,17 @@ TEST_CONSTEXPR_CXX20 bool test() { assert(dst.b_ == 2); assert(dst.c_ == 6); } - { // Make sure that overlapping ranges can be copied int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::move(a + 3, a + 10, a); int expected[] = {4, 5, 6, 7, 8, 9, 10, 8, 9, 10}; assert(std::equal(a, a + 10, expected)); } - - // Make sure that the algorithm works with move-only types - { + { // Make sure that the algorithm works with move-only types // When non-trivial { MoveOnly from[3] = {1, 2, 3}; - MoveOnly to[3] = {}; + MoveOnly to[3] = {}; std::move(std::begin(from), std::end(from), std::begin(to)); assert(to[0] == MoveOnly(1)); assert(to[1] == MoveOnly(2)); @@ -127,7 +124,7 @@ TEST_CONSTEXPR_CXX20 bool test() { // When trivial { TrivialMoveOnly from[3] = {1, 2, 3}; - TrivialMoveOnly to[3] = {}; + TrivialMoveOnly to[3] = {}; std::move(std::begin(from), std::end(from), std::begin(to)); assert(to[0] == TrivialMoveOnly(1)); assert(to[1] == TrivialMoveOnly(2)); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp index 61dea47b51071..d166c854f30aa 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/move_backward.pass.cpp @@ -23,6 +23,7 @@ #include "MoveOnly.h" #include "test_iterators.h" #include "test_macros.h" +#include "type_algorithms.h" class PaddedBase { public: @@ -44,24 +45,22 @@ struct Test { template TEST_CONSTEXPR_CXX20 void operator()() { const unsigned N = 1000; - int ia[N] = {}; + int ia[N] = {}; for (unsigned i = 0; i < N; ++i) - ia[i] = i; + ia[i] = i; int ib[N] = {0}; - OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N)); + OutIter r = std::move_backward(InIter(ia), InIter(ia + N), OutIter(ib + N)); assert(base(r) == ib); for (unsigned i = 0; i < N; ++i) - assert(ia[i] == ib[i]); + assert(ia[i] == ib[i]); } }; struct TestOutIters { template TEST_CONSTEXPR_CXX20 void operator()() { - types::for_each( - types::concatenate_t >(), - Test()); + types::for_each(types::concatenate_t >(), Test()); } }; @@ -72,21 +71,21 @@ struct Test1 { const unsigned N = 100; std::unique_ptr ia[N]; for (unsigned i = 0; i < N; ++i) - ia[i].reset(new int(i)); + ia[i].reset(new int(i)); std::unique_ptr ib[N]; - OutIter r = std::move_backward(InIter(ia), InIter(ia+N), OutIter(ib+N)); + OutIter r = std::move_backward(InIter(ia), InIter(ia + N), OutIter(ib + N)); assert(base(r) == ib); for (unsigned i = 0; i < N; ++i) - assert(*ib[i] == static_cast(i)); + assert(*ib[i] == static_cast(i)); } }; struct Test1OutIters { template TEST_CONSTEXPR_CXX23 void operator()() { - types::for_each(types::concatenate_t*> >(), - Test1()); + types::for_each( + types::concatenate_t*> >(), Test1()); } }; @@ -94,7 +93,6 @@ TEST_CONSTEXPR_CXX20 bool test() { types::for_each(types::bidirectional_iterator_list(), TestOutIters()); if (TEST_STD_AT_LEAST_23_OR_RUNTIME_EVALUATED) types::for_each(types::bidirectional_iterator_list*>(), Test1OutIters()); - { // Make sure that padding bits aren't copied Derived src(1, 2, 3); Derived dst(4, 5, 6); @@ -104,20 +102,17 @@ TEST_CONSTEXPR_CXX20 bool test() { assert(dst.b_ == 2); assert(dst.c_ == 6); } - { // Make sure that overlapping ranges can be copied int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; std::move_backward(a, a + 7, a + 10); int expected[] = {1, 2, 3, 1, 2, 3, 4, 5, 6, 7}; assert(std::equal(a, a + 10, expected)); } - - // Make sure that the algorithm works with move-only types - { + { // Make sure that the algorithm works with move-only types // When non-trivial { MoveOnly from[3] = {1, 2, 3}; - MoveOnly to[3] = {}; + MoveOnly to[3] = {}; std::move_backward(std::begin(from), std::end(from), std::end(to)); assert(to[0] == MoveOnly(1)); assert(to[1] == MoveOnly(2)); @@ -126,7 +121,7 @@ TEST_CONSTEXPR_CXX20 bool test() { // When trivial { TrivialMoveOnly from[3] = {1, 2, 3}; - TrivialMoveOnly to[3] = {}; + TrivialMoveOnly to[3] = {}; std::move_backward(std::begin(from), std::end(from), std::end(to)); assert(to[0] == TrivialMoveOnly(1)); assert(to[1] == TrivialMoveOnly(2)); @@ -137,8 +132,7 @@ TEST_CONSTEXPR_CXX20 bool test() { return true; } -int main(int, char**) -{ +int main(int, char**) { test(); #if TEST_STD_VER >= 20 static_assert(test()); diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/pstl.move.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/pstl.move.pass.cpp index e4cc5649ce5d8..a82a068caf031 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/pstl.move.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.move/pstl.move.pass.cpp @@ -23,6 +23,7 @@ #include "test_macros.h" #include "test_execution_policies.h" #include "test_iterators.h" +#include "type_algorithms.h" EXECUTION_POLICY_SFINAE_TEST(move);