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 @@ -21,7 +21,7 @@ #include "test_iterators.h" #if TEST_STD_VER > 17 -TEST_CONSTEXPR bool test_constexpr() { +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}; @@ -95,7 +95,8 @@ test(); #if TEST_STD_VER > 17 - static_assert(test_constexpr()); + assert(test_constexpr()); + static_assert(test_constexpr()); #endif 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 @@ -22,47 +22,46 @@ #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}; +constexpr bool test_constexpr() { + int ia[] = {4, 4, 4, 4, 3, 3, 3, 2, 2, 1}; + int ib[] = {4, 2}; int ic[] = {3, 3, 3, 3}; - auto comp = [](int a, int b) {return a < b; }; + auto comp = std::greater(); 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() { - 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**) @@ -98,7 +97,8 @@ test(); #if TEST_STD_VER > 17 - static_assert(test_constexpr()); + 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.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,21 @@ #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)); + + 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 + template void test() @@ -198,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.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,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, 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; }); + 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 + 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 +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.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,20 @@ #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; }) - ; - } + 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 - template void test() @@ -215,6 +212,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,38 @@ #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; }); + 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 - 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 +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.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,21 @@ #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)); + + 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 + template void test() @@ -197,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.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,20 @@ #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; }); + 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 + template void test() @@ -201,5 +215,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,21 @@ #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)); + + 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 + template void test() @@ -196,5 +211,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,39 @@ #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; }); + 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 + 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 +212,10 @@ test >(); test(); +#if TEST_STD_VER > 17 + assert(test_constexpr()); + static_assert(test_constexpr()); +#endif + return 0; }