From 85642c2bea823d5eed087ee64da030ab767fb00e Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 22 Jan 2018 00:11:44 +0000 Subject: implement (but leave commented out) the constexpr tests from P0202 for std::merge. merge requires std::copy, which isn't constexpr yet. llvm-svn: 323070 --- .../alg.sorting/alg.merge/merge.pass.cpp | 24 ++++++++++++++++++++- .../alg.sorting/alg.merge/merge_comp.pass.cpp | 25 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) (limited to 'libcxx/test/std/algorithms/alg.sorting') 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 index 777461023e7..4ebf3438933 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp @@ -15,15 +15,32 @@ // requires OutputIterator // && OutputIterator // && HasLess -// OutIter +// constexpr OutIter // constexpr after C++17 // merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, OutIter result); #include #include #include +#include "test_macros.h" #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)); + return std::distance(std::begin(ic), it) == (std::size(ia) + std::size(ib)) + && *it == 0 + && std::equal(std::begin(ic), it, std::begin(expected), std::end(expected)) + ; + } +#endif + std::mt19937 randomness; template @@ -224,4 +241,9 @@ int main() test >(); test >(); test(); + +#if TEST_STD_VER > 17 +// Not yet - waiting on std::copy +// 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 index 3daaeebbeae..b122fdfdb26 100644 --- 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 @@ -16,7 +16,7 @@ // requires OutputIterator // && OutputIterator // && CopyConstructible -// OutIter +// constexpr OutIter // constexpr after C++17 // merge(InIter1 first1, InIter1 last1, // InIter2 first2, InIter2 last2, OutIter result, Compare comp); @@ -25,9 +25,27 @@ #include #include +#include "test_macros.h" #include "test_iterators.h" #include "counting_predicates.hpp" +#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), [](int a, int b) {return a == b; }); + return std::distance(std::begin(ic), it) == (std::size(ia) + std::size(ib)) + && *it == 0 + && std::equal(std::begin(ic), it, std::begin(expected), std::end(expected)) + ; + } +#endif + std::mt19937 randomness; template @@ -234,4 +252,9 @@ int main() test >(); test >(); test(); + +#if TEST_STD_VER > 17 +// Not yet - waiting on std::copy +// static_assert(test_constexpr()); +#endif } -- cgit v1.2.3