From bb8010f6f23d13f2eeb160c30933c2e12d62b774 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 15 Jan 2018 17:53:34 +0000 Subject: [PATCH] partition_point gets the P0202 treatment git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@322493 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/algorithm | 4 ++-- .../alg.partitions/partition_point.pass.cpp | 21 +++++++++++++++++-- .../alg.all_of/all_of.pass.cpp | 2 +- .../alg.any_of/any_of.pass.cpp | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/algorithm b/include/algorithm index 3d8bf7a4b..f357177e6 100644 --- a/include/algorithm +++ b/include/algorithm @@ -321,7 +321,7 @@ template stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); template - ForwardIterator + ForwardIterator // constexpr in C++20 partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); template @@ -3328,7 +3328,7 @@ partition_copy(_InputIterator __first, _InputIterator __last, // partition_point template -_ForwardIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) { typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type; diff --git a/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp b/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp index f5b832c66..a08912bad 100644 --- a/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp +++ b/test/std/algorithms/alg.modifying.operations/alg.partitions/partition_point.pass.cpp @@ -10,19 +10,32 @@ // // template -// ForwardIterator +// constpexr ForwardIterator // constexpr after C++17 // partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); #include #include +#include "test_macros.h" #include "test_iterators.h" struct is_odd { - bool operator()(const int& i) const {return i & 1;} + TEST_CONSTEXPR bool operator()(const int& i) const {return i & 1;} }; + +#if TEST_STD_VER > 17 +TEST_CONSTEXPR int test_constexpr() { + int ia[] = {1, 3, 5, 2, 4, 6}; + int ib[] = {1, 2, 3, 4, 5, 6}; + return (std::partition_point(std::begin(ia), std::end(ia), is_odd()) == ia+3) + && (std::partition_point(std::begin(ib), std::end(ib), is_odd()) == ib+1) + ; + } +#endif + + int main() { { @@ -73,4 +86,8 @@ int main() forward_iterator(std::begin(ia)), is_odd()) == forward_iterator(ia)); } + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp index 5896b40ae..0a5998105 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.all_of/all_of.pass.cpp @@ -10,7 +10,7 @@ // // template -// bool +// constpexr bool // constexpr after C++17 // all_of(InputIterator first, InputIterator last, Predicate pred); #include diff --git a/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp index 5256270a3..d21a691e7 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.any_of/any_of.pass.cpp @@ -10,7 +10,7 @@ // // template -// bool +// constpexr bool // constexpr after C++17 // any_of(InputIterator first, InputIterator last, Predicate pred); #include