diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2018-01-15 19:26:05 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2018-01-15 19:26:05 +0000 |
commit | 8694428e365648723f5519af0a6818eb24ecb990 (patch) | |
tree | 633b962ba16be5e53395023779e649ab6bcc090c /libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end | |
parent | b60f1b6d3debbbdbcd057d763fbef7e2492718a3 (diff) | |
download | bcm5719-llvm-8694428e365648723f5519af0a6818eb24ecb990.tar.gz bcm5719-llvm-8694428e365648723f5519af0a6818eb24ecb990.zip |
More P0202 constexpr-ifying. All the find_XXX algorithms in this commit.
llvm-svn: 322504
Diffstat (limited to 'libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end')
-rw-r--r-- | libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp | 26 | ||||
-rw-r--r-- | libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp | 28 |
2 files changed, 51 insertions, 3 deletions
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp index e95162b4ad7..bc5d50cd5dd 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp @@ -11,14 +11,34 @@ // template<ForwardIterator Iter1, ForwardIterator Iter2> // requires HasEqualTo<Iter1::value_type, Iter2::value_type> -// Iter1 +// constexpr Iter1 // constexpr after C++17 // find_end(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2); #include <algorithm> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {0, 1, 2}; + int ib[] = {4, 5, 6}; + int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0}; + typedef forward_iterator<int*> FI; + typedef bidirectional_iterator<int*> BI; + typedef random_access_iterator<int*> RI; + + return (std::find_end(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia))) == FI(ic+15)) + && (std::find_end(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib))) == FI(std::end(ic))) + && (std::find_end(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia))) == BI(ic+15)) + && (std::find_end(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib))) == BI(std::end(ic))) + && (std::find_end(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia))) == RI(ic+15)) + && (std::find_end(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib))) == RI(std::end(ic))) + ; + } +#endif + template <class Iter1, class Iter2> void test() @@ -54,4 +74,8 @@ int main() test<random_access_iterator<const int*>, forward_iterator<const int*> >(); test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp index 411858d5b76..595e1bb1885 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp @@ -12,22 +12,42 @@ // template<ForwardIterator Iter1, ForwardIterator Iter2, // Predicate<auto, Iter1::value_type, Iter2::value_type> Pred> // requires CopyConstructible<Pred> -// Iter1 +// constexpr Iter1 // constexpr after C++17 // find_end(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Pred pred); #include <algorithm> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" struct count_equal { static unsigned count; template <class T> - bool operator()(const T& x, const T& y) + TEST_CONSTEXPR bool operator()(const T& x, const T& y) {++count; return x == y;} }; +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {0, 1, 2}; + int ib[] = {4, 5, 6}; + int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0}; + typedef forward_iterator<int*> FI; + typedef bidirectional_iterator<int*> BI; + typedef random_access_iterator<int*> RI; + std::equal_to<int> eq; + return (std::find_end(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia)), eq) == FI(ic+15)) + && (std::find_end(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib)), eq) == FI(std::end(ic))) + && (std::find_end(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia)), eq) == BI(ic+15)) + && (std::find_end(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib)), eq) == BI(std::end(ic))) + && (std::find_end(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia)), eq) == RI(ic+15)) + && (std::find_end(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib)), eq) == RI(std::end(ic))) + ; + } +#endif + unsigned count_equal::count = 0; template <class Iter1, class Iter2> @@ -83,4 +103,8 @@ int main() test<random_access_iterator<const int*>, forward_iterator<const int*> >(); test<random_access_iterator<const int*>, bidirectional_iterator<const int*> >(); test<random_access_iterator<const int*>, random_access_iterator<const int*> >(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } |