diff options
| author | Marshall Clow <mclow.lists@gmail.com> | 2018-01-22 23:10:40 +0000 |
|---|---|---|
| committer | Marshall Clow <mclow.lists@gmail.com> | 2018-01-22 23:10:40 +0000 |
| commit | 8da1a487aec015cf65479861c21411319be468d2 (patch) | |
| tree | 93e800f58f46303b59a62e461fd26716d70a429c /libcxx/test/std/algorithms/alg.sorting | |
| parent | 239d25a1585d3249f3918bb444fc77424b2ec052 (diff) | |
| download | bcm5719-llvm-8da1a487aec015cf65479861c21411319be468d2.tar.gz bcm5719-llvm-8da1a487aec015cf65479861c21411319be468d2.zip | |
Last batch of P0202 constexpr additions: includes/set_intersection/exchange
llvm-svn: 323159
Diffstat (limited to 'libcxx/test/std/algorithms/alg.sorting')
4 files changed, 87 insertions, 4 deletions
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp index 70abd180975..60a5d2bd7a3 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes.pass.cpp @@ -12,14 +12,27 @@ // template<InputIterator Iter1, InputIterator Iter2> // requires HasLess<Iter1::value_type, Iter2::value_type> // && HasLess<Iter2::value_type, Iter1::value_type> -// bool +// constexpr bool // constexpr after C++17 // includes(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[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + int ib[] = {2, 4}; + int ic[] = {3, 3, 3, 3}; + + return std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib)) + && !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic)) + ; + } +#endif + template <class Iter1, class Iter2> void test() @@ -81,4 +94,8 @@ int main() test<const int*, bidirectional_iterator<const int*> >(); test<const int*, random_access_iterator<const int*> >(); test<const int*, const int*>(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp index 299dc893560..82cf043d3e5 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/includes/includes_comp.pass.cpp @@ -12,15 +12,30 @@ // template<InputIterator Iter1, InputIterator Iter2, typename Compare> // requires Predicate<Compare, Iter1::value_type, Iter2::value_type> // && Predicate<Compare, Iter2::value_type, Iter1::value_type> -// bool +// constexpr bool // constexpr after C++17 // includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Compare comp); #include <algorithm> #include <functional> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + int ib[] = {2, 4}; + int ic[] = {3, 3, 3, 3}; + + auto comp = [](int a, int b) {return a < b; }; + return std::includes(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), comp) + && !std::includes(std::begin(ia), std::end(ia), std::begin(ic), std::end(ic), comp) + ; + } +#endif + + template <class Iter1, class Iter2> void test() @@ -82,4 +97,8 @@ int main() test<const int*, bidirectional_iterator<const int*> >(); test<const int*, random_access_iterator<const int*> >(); test<const int*, const int*>(); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp index f371890d8e7..96a1eae8d29 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection.pass.cpp @@ -14,15 +14,34 @@ // && OutputIterator<OutIter, InIter2::reference> // && HasLess<InIter2::value_type, InIter1::value_type> // && HasLess<InIter1::value_type, InIter2::value_type> -// OutIter +// constpexr OutIter // constexpr after C++17 // set_intersection(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, // OutIter result); #include <algorithm> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + const int ib[] = {2, 4, 4, 6}; + int results[std::size(ia)] = {0}; + + auto it = std::set_intersection(std::begin(ia), std::end(ia), + std::begin(ib), std::end(ib), std::begin(results)); + + return std::includes(std::begin(ia), std::end(ia), std::begin(results), it) + && std::includes(std::begin(ib), std::end(ib), std::begin(results), it) + && std::is_sorted(std::begin(results), it) + && std::all_of(it, std::end(results), [](int a) {return a == 0; }) + ; + } +#endif + + template <class Iter1, class Iter2, class OutIter> void test() @@ -195,4 +214,8 @@ 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 + static_assert(test_constexpr()); +#endif } diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp index 035522b5462..75316921c29 100644 --- a/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp +++ b/libcxx/test/std/algorithms/alg.sorting/alg.set.operations/set.intersection/set_intersection_comp.pass.cpp @@ -15,7 +15,7 @@ // && OutputIterator<OutIter, InIter2::reference> // && Predicate<Compare, InIter1::value_type, InIter2::value_type> // && Predicate<Compare, InIter2::value_type, InIter1::value_type> -// OutIter +// constpexr OutIter // constexpr after C++17 // set_intersection(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, // OutIter result, Compare comp); @@ -23,8 +23,28 @@ #include <functional> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" +#if TEST_STD_VER > 17 +TEST_CONSTEXPR bool test_constexpr() { + const int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4}; + const int ib[] = {2, 4, 4, 6}; + int results[std::size(ia)] = {0}; + + auto comp = [](int a, int b) {return a < b; }; + auto it = std::set_intersection(std::begin(ia), std::end(ia), + std::begin(ib), std::end(ib), std::begin(results), comp); + + return std::includes(std::begin(ia), std::end(ia), std::begin(results), it) + && std::includes(std::begin(ib), std::end(ib), std::begin(results), it) + && std::is_sorted(std::begin(results), it, comp) + && std::all_of(it, std::end(results), [](int a) {return a == 0; }) + ; + } +#endif + + template <class Iter1, class Iter2, class OutIter> void test() @@ -197,4 +217,8 @@ 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 + static_assert(test_constexpr()); +#endif } |

