diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm index c00845f6404b..3dda30d15108 100644 --- a/libcxx/include/algorithm +++ b/libcxx/include/algorithm @@ -236,19 +236,19 @@ template generate_n(OutputIterator first, Size n, Generator gen); template - ForwardIterator + constexpr ForwardIterator // constexpr in C++20 remove(ForwardIterator first, ForwardIterator last, const T& value); template - ForwardIterator + constexpr ForwardIterator // constexpr in C++20 remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); template @@ -272,7 +272,7 @@ template reverse(BidirectionalIterator first, BidirectionalIterator last); template - OutputIterator + constexpr OutputIterator // constexpr in C++20 reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); template @@ -2098,7 +2098,7 @@ generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) // remove template -_ForwardIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { __first = _VSTD::find(__first, __last, __value_); @@ -2120,7 +2120,7 @@ remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) // remove_if template -_ForwardIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { __first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type> @@ -2143,7 +2143,7 @@ remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) // remove_copy template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_) { @@ -2161,7 +2161,7 @@ remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __res // remove_copy_if template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred) { @@ -2327,7 +2327,7 @@ reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) // reverse_copy template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) { diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp index a77a9eddb191..557984f3900c 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove.pass.cpp @@ -12,7 +12,7 @@ // template // requires OutputIterator::type> // && HasEqualTo -// Iter +// constexpr Iter // constexpr after C++17 // remove(Iter first, Iter last, const T& value); #include @@ -22,6 +22,18 @@ #include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {1, 3, 5, 2, 5, 6}; + + auto it = std::remove(std::begin(ia), std::end(ia), 5); + + return (std::begin(ia) + std::size(ia) - 2) == it // we removed two elements + && std::none_of(std::begin(ia), it, [](int a) {return a == 5; }) + ; + } +#endif + template void test() @@ -75,4 +87,8 @@ int main() test1*> >(); test1*>(); #endif // TEST_STD_VER >= 11 + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp index bf5f79cf8359..ae7b34184264 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy.pass.cpp @@ -11,14 +11,29 @@ // template OutIter, class T> // requires HasEqualTo -// OutIter +// constexpr OutIter // constexpr after C++17 // remove_copy(InIter first, InIter last, OutIter result, const T& value); #include #include +#include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {1, 3, 5, 2, 5, 6}; + int ib[std::size(ia)] = {0}; + + auto it = std::remove_copy(std::begin(ia), std::end(ia), std::begin(ib), 5); + + return std::distance(std::begin(ib), it) == (std::size(ia) - 2) // we removed two elements + && std::none_of(std::begin(ib), it, [](int a) {return a == 5;}) + && std::all_of (it, std::end(ib), [](int a) {return a == 0;}) + ; + } +#endif + template void test() @@ -67,4 +82,8 @@ int main() test >(); test >(); test(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp index 8532998eb08d..111c59eb795b 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_copy_if.pass.cpp @@ -12,16 +12,31 @@ // template OutIter, // Predicate Pred> // requires CopyConstructible -// OutIter +// constexpr OutIter // constexpr after C++17 // remove_copy_if(InIter first, InIter last, OutIter result, Pred pred); #include #include #include +#include "test_macros.h" #include "test_iterators.h" -bool equalToTwo(int v) { return v == 2; } +TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; } + +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {1, 3, 5, 2, 5, 6}; + int ib[std::size(ia)] = {0}; + + auto it = std::remove_copy_if(std::begin(ia), std::end(ia), std::begin(ib), equalToTwo); + + return std::distance(std::begin(ib), it) == (std::size(ia) - 1) // we removed one element + && std::none_of(std::begin(ib), it, equalToTwo) + && std::all_of (it, std::end(ib), [](int a) {return a == 0;}) + ; + } +#endif template void @@ -72,4 +87,8 @@ int main() test >(); test >(); test(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp index c40f3e727836..d8123ee4540c 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.remove/remove_if.pass.cpp @@ -12,7 +12,7 @@ // template Pred> // requires OutputIterator::type> // && CopyConstructible -// Iter +// constexpr Iter // constexpr after C++17 // remove_if(Iter first, Iter last, Pred pred); #include @@ -24,7 +24,19 @@ #include "test_iterators.h" #include "counting_predicates.hpp" -bool equal2 ( int i ) { return i == 2; } +TEST_CONSTEXPR bool equal2 ( int i ) { return i == 2; } + +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {1, 3, 5, 2, 5, 6}; + + auto it = std::remove_if(std::begin(ia), std::end(ia), equal2); + + return (std::begin(ia) + std::size(ia) - 1) == it // we removed one element + && std::none_of(std::begin(ia), it, equal2) + ; + } +#endif template void @@ -90,4 +102,8 @@ int main() test1*> >(); test1*>(); #endif // TEST_STD_VER >= 11 + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp index 70840d187bfb..ec9aa9e94ab8 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.reverse/reverse_copy.pass.cpp @@ -10,14 +10,28 @@ // // template OutIter> -// OutIter +// constexpr OutIter // constexpr after C++17 // reverse_copy(InIter first, InIter last, OutIter result); #include #include +#include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {1, 3, 5, 2, 5, 6}; + int ib[std::size(ia)] = {0}; + + auto it = std::reverse_copy(std::begin(ia), std::end(ia), std::begin(ib)); + + return std::distance(std::begin(ib), it) == std::size(ia) + && std::equal (std::begin(ia), std::end(ia), std::rbegin(ib)) + ; + } +#endif + template void test() @@ -78,4 +92,8 @@ int main() test >(); test >(); test(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp index f2ad535a2f99..2294c79b5fad 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.rotate/rotate_copy.pass.cpp @@ -10,14 +10,31 @@ // // template OutIter> -// OutIter +// constexpr OutIter // constexpr after C++17 // rotate_copy(InIter first, InIter middle, InIter last, OutIter result); #include #include +#include "test_macros.h" #include "test_iterators.h" +// #if TEST_STD_VER > 17 +// TEST_CONSTEXPR bool test_constexpr() { +// int ia[] = {1, 3, 5, 2, 5, 6}; +// int ib[std::size(ia)] = {0}; +// +// const size_t N = 2; +// const auto middle = std::begin(ia) + N; +// auto it = std::rotate_copy(std::begin(ia), middle, std::end(ia), std::begin(ib)); +// +// return std::distance(std::begin(ib), it) == std::size(ia) +// && std::equal (std::begin(ia), middle, std::begin(ib) + std::size(ia) - N) +// && std::equal (middle, std::end(ia), std::begin(ib)) +// ; +// } +// #endif + template void test() @@ -131,4 +148,8 @@ int main() test >(); test >(); test(); + +// #if TEST_STD_VER > 17 +// static_assert(test_constexpr()); +// #endif }