diff --git a/libcxx/docs/Cxx2aStatus.rst b/libcxx/docs/Cxx2aStatus.rst --- a/libcxx/docs/Cxx2aStatus.rst +++ b/libcxx/docs/Cxx2aStatus.rst @@ -38,7 +38,6 @@ .. note:: - .. [#note-P0202] P0202: The missing bits in P0202 are in ``copy`` and ``copy_backwards`` (and the ones that call them: ``copy_n``, ``set_union``, ``set_difference``, and ``set_symmetric_difference``). This is because the first two algorithms have specializations that call ``memmove`` which is not constexpr. See `Bug 25165 `__ .. [#note-P0600] P0600: The missing bits in P0600 are in |sect|\ [mem.res.class], |sect|\ [mem.poly.allocator.class], and |sect|\ [container.node.overview]. .. [#note-P0966] P0966: It was previously erroneously marked as complete in version 8.0. See `bug 45368 `__. diff --git a/libcxx/docs/Cxx2aStatusPaperStatus.csv b/libcxx/docs/Cxx2aStatusPaperStatus.csv --- a/libcxx/docs/Cxx2aStatusPaperStatus.csv +++ b/libcxx/docs/Cxx2aStatusPaperStatus.csv @@ -4,7 +4,7 @@ "","","","","","" "`P0020R6 `__","LWG","Floating Point Atomic","Albuquerque","","" "`P0053R7 `__","LWG","C++ Synchronized Buffered Ostream","Albuquerque","","" -"`P0202R3 `__","LWG","Add constexpr modifiers to functions in and Headers","Albuquerque","|In Progress| [#note-P0202]_","7.0" +"`P0202R3 `__","LWG","Add constexpr modifiers to functions in and Headers","Albuquerque","|Complete|","" "`P0415R1 `__","LWG","Constexpr for ``std::complex``\ ","Albuquerque","|In Progress|","7.0" "`P0439R0 `__","LWG","Make ``std::memory_order``\ a scoped enumeration","Albuquerque","|Complete|","" "`P0457R2 `__","LWG","String Prefix and Suffix Checking","Albuquerque","|Complete|","6.0" diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -415,12 +415,12 @@ binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 merge(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); @@ -441,12 +441,12 @@ includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 set_union(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); @@ -461,22 +461,22 @@ InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 set_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); @@ -5401,7 +5401,7 @@ // set_union template -_OutputIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator __set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { @@ -5426,7 +5426,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) @@ -5436,7 +5436,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_union(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) @@ -5495,7 +5495,7 @@ // set_difference template -_OutputIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator __set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { @@ -5520,7 +5520,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) @@ -5530,7 +5530,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) @@ -5543,7 +5543,7 @@ // set_symmetric_difference template -_OutputIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator __set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) { @@ -5573,7 +5573,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) @@ -5583,7 +5583,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp @@ -29,18 +29,16 @@ #include "test_iterators.h" #if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { - int ia[] = {0, 1, 2, 3, 4}; - int ib[] = {2, 4, 6, 8}; - int ic[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const int expected[] = {0, 1, 2, 2, 3, 4, 4, 6, 8}; - - auto it = std::merge(std::begin(ia), std::end(ia), std::begin(ib), - std::end(ib), std::begin(ic)); - assert(std::distance(std::begin(ic), it) == static_cast(std::size(ia) + std::size(ib))); - assert(*it == 0); - assert(std::equal(std::begin(ic), it, std::begin(expected), std::end(expected))); - return true; +constexpr bool test_constexpr() { + const int ia[] = {0, 1, 2, 3, 4}; + const int ib[] = {2, 4, 6, 8}; + int results[10] = {0}; + const int expected[] = {0, 1, 2, 2, 3, 4, 4, 6, 8}; + + auto it = std::merge(std::begin(ia), std::end(ia), std::begin(ib), + std::end(ib), std::begin(results)); + return std::equal(std::begin(results), it, std::begin(expected), std::end(expected)) && + std::all_of(it, std::end(results), [](int a) { return a == 0; }); } #endif @@ -244,6 +242,7 @@ test(); #if TEST_STD_VER > 17 + assert(test_constexpr()); static_assert(test_constexpr()); #endif diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp @@ -33,20 +33,16 @@ #include "counting_predicates.h" #if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { - int ia[] = {0, 1, 2, 3, 4}; - int ib[] = {2, 4, 6, 8}; - int ic[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - const int expected[] = {0, 1, 2, 2, 3, 4, 4, 6, 8}; - - auto it = - std::merge(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), - std::begin(ic), std::less<>{}); - assert(std::distance(std::begin(ic), it) == static_cast(std::size(ia) + std::size(ib))); - assert(*it == 0); - assert( - std::equal(std::begin(ic), it, std::begin(expected), std::end(expected))); - return true; +constexpr bool test_constexpr() { + const int ia[] = {11, 33, 31, 41}; + const int ib[] = {22, 32, 43, 42, 52}; + int results[10] = {0}; + const int expected[] = {11, 22, 33, 31, 32, 41, 43, 42, 52}; + + auto it = std::merge(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), + std::begin(results), [](int a, int b){ return a/10 < b/10; }); + return std::equal(std::begin(results), it, std::begin(expected), std::end(expected)) && + std::all_of(it, std::end(results), [](int a) { return a == 0; }); } #endif @@ -258,6 +254,7 @@ test(); #if TEST_STD_VER > 17 + assert(test_constexpr()); static_assert(test_constexpr()); #endif diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp @@ -20,21 +20,9 @@ #include "test_macros.h" #include "test_iterators.h" -#if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { - int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; - int ib[] = {2, 4}; - int ic[] = {3, 3, 3, 3}; - - return std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib)) - && !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic)) - ; - } -#endif - template -void -test() +TEST_CONSTEXPR_CXX20 +void test() { int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); @@ -62,7 +50,8 @@ assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4))); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 +bool do_tests() { test, input_iterator >(); test, forward_iterator >(); @@ -94,9 +83,14 @@ test >(); test(); + return true; +} + +int main(int, char**) +{ + do_tests(); #if TEST_STD_VER > 17 - static_assert(test_constexpr()); + static_assert(do_tests()); #endif - - return 0; + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp @@ -21,51 +21,38 @@ #include "test_macros.h" #include "test_iterators.h" -#if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { - int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; - int ib[] = {2, 4}; - int ic[] = {3, 3, 3, 3}; - - auto comp = [](int a, int b) {return a < b; }; - return std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), comp) - && !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic), comp) - ; - } -#endif - - template -void -test() +TEST_CONSTEXPR_CXX20 +void test() { - int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); - int ib[] = {2, 4}; + int ib[] = {4, 2}; const unsigned sb = sizeof(ib)/sizeof(ib[0]); - int ic[] = {1, 2}; + int ic[] = {2, 1}; const unsigned sc = sizeof(ic)/sizeof(ic[0]); ((void)sc); int id[] = {3, 3, 3, 3}; const unsigned sd = sizeof(id)/sizeof(id[0]); ((void)sd); - assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::less())); - assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::less())); - assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::less())); - assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::less())); + assert(std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib), std::greater())); + assert(!std::includes(Iter1(ia), Iter1(ia), Iter2(ib), Iter2(ib+1), std::greater())); + assert(std::includes(Iter1(ia), Iter1(ia+1), Iter2(ib), Iter2(ib), std::greater())); + assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa), std::greater())); - assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::less())); - assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::less())); + assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::greater())); + assert(!std::includes(Iter1(ib), Iter1(ib+sb), Iter2(ia), Iter2(ia+sa), std::greater())); - assert(std::includes(Iter1(ia), Iter1(ia+2), Iter2(ic), Iter2(ic+2), std::less())); - assert(!std::includes(Iter1(ia), Iter1(ia+2), Iter2(ib), Iter2(ib+2), std::less())); + assert(std::includes(Iter1(ia+8), Iter1(ia+sa), Iter2(ic), Iter2(ic+sc), std::greater())); + assert(!std::includes(Iter1(ia+8), Iter1(ia+sa), Iter2(ib), Iter2(ib+sb), std::greater())); - assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::less())); - assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::less())); - assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::less())); - assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::less())); + assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+1), std::greater())); + assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+2), std::greater())); + assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+3), std::greater())); + assert(!std::includes(Iter1(ia), Iter1(ia+sa), Iter2(id), Iter2(id+4), std::greater())); } -int main(int, char**) +TEST_CONSTEXPR_CXX20 +bool do_tests() { test, input_iterator >(); test, forward_iterator >(); @@ -97,9 +84,14 @@ test >(); test(); + return true; +} + +int main(int, char**) +{ + do_tests(); #if TEST_STD_VER > 17 - static_assert(test_constexpr()); + static_assert(do_tests()); #endif - - return 0; + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference.pass.cpp @@ -23,6 +23,22 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +constexpr bool test_constexpr() { + const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + const int ib[] = {2, 4, 4, 6}; + int results[10] = {0}; + const int expected[] = {1, 2, 3, 3, 3, 4, 4}; + + auto it = std::set_difference(std::begin(ia), std::end(ia), + std::begin(ib), std::end(ib), std::begin(results)); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} +#endif + template void test() @@ -198,5 +214,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.difference/set_difference_comp.pass.cpp @@ -25,27 +25,43 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +constexpr bool test_constexpr() { + const int ia[] = {11, 33, 31, 41}; + const int ib[] = {22, 32, 43, 42, 52}; + int results[10] = {0}; + const int expected[] = {11, 31}; + + auto it = std::set_difference(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), + std::begin(results), [](int a, int b){ return a/10 < b/10; }); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} +#endif + template void test() { - int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; const int sa = sizeof(ia)/sizeof(ia[0]); - int ib[] = {2, 4, 4, 6}; + int ib[] = {6, 4, 4, 2}; const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; - int ir[] = {1, 2, 3, 3, 3, 4, 4}; + int ir[] = {4, 4, 3, 3, 3, 2, 1}; const int sr = sizeof(ir)/sizeof(ir[0]); OutIter ce = std::set_difference(Iter1(ia), Iter1(ia+sa), - Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less()); + Iter2(ib), Iter2(ib+sb), OutIter(ic), std::greater()); assert(base(ce) - ic == sr); - assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0); + assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr, std::greater()) == 0); int irr[] = {6}; const int srr = sizeof(irr)/sizeof(irr[0]); ce = std::set_difference(Iter1(ib), Iter1(ib+sb), - Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less()); + Iter2(ia), Iter2(ia+sa), OutIter(ic), std::greater()); assert(base(ce) - ic == srr); - assert(std::lexicographical_compare(ic, base(ce), irr, irr+srr) == 0); + assert(std::lexicographical_compare(ic, base(ce), irr, irr+srr, std::greater()) == 0); } int main(int, char**) @@ -200,5 +216,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp @@ -24,23 +24,21 @@ #include "test_iterators.h" #if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { +constexpr bool test_constexpr() { const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; const int ib[] = {2, 4, 4, 6}; - int results[std::size(ia)] = {0}; + int results[10] = {0}; + const int expected[] = {2, 4, 4}; auto it = std::set_intersection(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), std::begin(results)); - return std::includes(std::begin(ia), std::end(ia), std::begin(results), it) - && std::includes(std::begin(ib), std::end(ib), std::begin(results), it) - && std::is_sorted(std::begin(results), it) - && std::all_of(it, std::end(results), [](int a) {return a == 0; }) - ; - } + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} #endif - template void test() @@ -215,6 +213,7 @@ test(); #if TEST_STD_VER > 17 + assert(test_constexpr()); static_assert(test_constexpr()); #endif diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp @@ -26,43 +26,40 @@ #include "test_iterators.h" #if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { - const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; - const int ib[] = {2, 4, 4, 6}; - int results[std::size(ia)] = {0}; - - auto comp = [](int a, int b) {return a < b; }; - auto it = std::set_intersection(std::begin(ia), std::end(ia), - std::begin(ib), std::end(ib), std::begin(results), comp); - - return std::includes(std::begin(ia), std::end(ia), std::begin(results), it) - && std::includes(std::begin(ib), std::end(ib), std::begin(results), it) - && std::is_sorted(std::begin(results), it, comp) - && std::all_of(it, std::end(results), [](int a) {return a == 0; }) - ; - } +constexpr bool test_constexpr() { + const int ia[] = {11, 33, 31, 41}; + const int ib[] = {22, 32, 43, 42, 52}; + int results[10] = {0}; + const int expected[] = {33, 41}; + + auto it = std::set_intersection(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), + std::begin(results), [](int a, int b){ return a/10 < b/10; }); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} #endif - template void test() { - int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; const int sa = sizeof(ia)/sizeof(ia[0]); - int ib[] = {2, 4, 4, 6}; + int ib[] = {6, 4, 4, 2}; const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; - int ir[] = {2, 4, 4}; + int ir[] = {4, 4, 2}; const int sr = sizeof(ir)/sizeof(ir[0]); OutIter ce = std::set_intersection(Iter1(ia), Iter1(ia+sa), - Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less()); + Iter2(ib), Iter2(ib+sb), OutIter(ic), std::greater()); assert(base(ce) - ic == sr); - assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0); + assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr, std::greater()) == 0); ce = std::set_intersection(Iter1(ib), Iter1(ib+sb), - Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less()); + Iter2(ia), Iter2(ia+sa), OutIter(ic), std::greater()); assert(base(ce) - ic == sr); - assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0); + assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr, std::greater()) == 0); } int main(int, char**) @@ -218,6 +215,7 @@ test(); #if TEST_STD_VER > 17 + assert(test_constexpr()); static_assert(test_constexpr()); #endif diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference.pass.cpp @@ -24,6 +24,22 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +constexpr bool test_constexpr() { + const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + const int ib[] = {2, 4, 4, 6}; + int results[10] = {0}; + const int expected[] = {1, 2, 3, 3, 3, 4, 4, 6}; + + auto it = std::set_symmetric_difference(std::begin(ia), std::end(ia), + std::begin(ib), std::end(ib), std::begin(results)); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} +#endif + template void test() @@ -197,5 +213,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.symmetric.difference/set_symmetric_difference_comp.pass.cpp @@ -26,6 +26,22 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +constexpr bool test_constexpr() { + const int ia[] = {11, 33, 31, 41}; + const int ib[] = {22, 32, 43, 42, 52}; + int results[10] = {0}; + const int expected[] = {11, 22, 31, 42, 52}; + + auto it = std::set_symmetric_difference(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), + std::begin(results), [](int a, int b){ return a/10 < b/10; }); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} +#endif + template void test() @@ -201,5 +217,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union.pass.cpp @@ -23,6 +23,22 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +constexpr bool test_constexpr() { + const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + const int ib[] = {2, 4, 4, 6}; + int results[20] = {0}; + const int expected[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; + + auto it = std::set_union(std::begin(ia), std::end(ia), + std::begin(ib), std::end(ib), std::begin(results)); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} +#endif + template void test() @@ -196,5 +212,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_comp.pass.cpp @@ -25,25 +25,41 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +constexpr bool test_constexpr() { + const int ia[] = {11, 33, 31, 41}; + const int ib[] = {22, 32, 43, 42, 52}; + int results[10] = {0}; + const int expected[] = {11, 22, 33, 31, 41, 42, 52}; + + auto it = std::set_union(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), + std::begin(results), [](int a, int b){ return a/10 < b/10; }); + + assert(std::equal(std::begin(results), it, std::begin(expected), std::end(expected))); + assert(std::all_of(it, std::end(results), [](int a) { return a == 0; })); + return true; +} +#endif + template void test() { - int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; const int sa = sizeof(ia)/sizeof(ia[0]); - int ib[] = {2, 4, 4, 6}; + int ib[] = {6, 4, 4, 2}; const int sb = sizeof(ib)/sizeof(ib[0]); int ic[20]; - int ir[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 6}; + int ir[] = {6, 4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; const int sr = sizeof(ir)/sizeof(ir[0]); OutIter ce = std::set_union(Iter1(ia), Iter1(ia+sa), - Iter2(ib), Iter2(ib+sb), OutIter(ic), std::less()); + Iter2(ib), Iter2(ib+sb), OutIter(ic), std::greater()); assert(base(ce) - ic == sr); - assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0); + assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr, std::greater()) == 0); ce = std::set_union(Iter1(ib), Iter1(ib+sb), - Iter2(ia), Iter2(ia+sa), OutIter(ic), std::less()); + Iter2(ia), Iter2(ia+sa), OutIter(ic), std::greater()); assert(base(ce) - ic == sr); - assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr) == 0); + assert(std::lexicographical_compare(ic, base(ce), ir, ir+sr, std::greater()) == 0); } int main(int, char**) @@ -198,5 +214,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; }