Author: marshall Date: Sun Jan 21 16:11:44 2018 New Revision: 323070 URL: http://llvm.org/viewvc/llvm-project?rev=323070&view=rev Log: implement (but leave commented out) the constexpr tests from P0202 for std::merge. merge requires std::copy, which isn't constexpr yet.
Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp?rev=323070&r1=323069&r2=323070&view=diff ============================================================================== --- libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp (original) +++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge.pass.cpp Sun Jan 21 16:11:44 2018 @@ -15,15 +15,32 @@ // requires OutputIterator<OutIter, InIter1::reference> // && OutputIterator<OutIter, InIter2::reference> // && HasLess<InIter2::value_type, InIter1::value_type> -// OutIter +// constexpr OutIter // constexpr after C++17 // merge(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, OutIter result); #include <algorithm> #include <random> #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, 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 <class InIter1, class InIter2, class OutIter> @@ -224,4 +241,9 @@ int main() test<const int*, const int*, bidirectional_iterator<int*> >(); test<const int*, const int*, random_access_iterator<int*> >(); test<const int*, const int*, int*>(); + +#if TEST_STD_VER > 17 +// Not yet - waiting on std::copy +// static_assert(test_constexpr()); +#endif } Modified: libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp?rev=323070&r1=323069&r2=323070&view=diff ============================================================================== --- libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp (original) +++ libcxx/trunk/test/std/algorithms/alg.sorting/alg.merge/merge_comp.pass.cpp Sun Jan 21 16:11:44 2018 @@ -16,7 +16,7 @@ // requires OutputIterator<OutIter, InIter1::reference> // && OutputIterator<OutIter, InIter2::reference> // && CopyConstructible<Compare> -// 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 <random> #include <cassert> +#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 <class InIter1, class InIter2, class OutIter> @@ -234,4 +252,9 @@ int main() test<const int*, const int*, bidirectional_iterator<int*> >(); test<const int*, const int*, random_access_iterator<int*> >(); test<const int*, const int*, int*>(); + +#if TEST_STD_VER > 17 +// Not yet - waiting on std::copy +// static_assert(test_constexpr()); +#endif } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits