summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms/alg.sorting
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2018-01-22 20:44:33 +0000
committerMarshall Clow <mclow.lists@gmail.com>2018-01-22 20:44:33 +0000
commit1b9a4ffd6bb2622360e6bae10bbcce7348186e94 (patch)
tree5a14c13574c3b1180031bd6aefdc1427cf9446a8 /libcxx/test/std/algorithms/alg.sorting
parentd7d991e881fb3f74325a13cc80cc5467eb43af65 (diff)
downloadbcm5719-llvm-1b9a4ffd6bb2622360e6bae10bbcce7348186e94.tar.gz
bcm5719-llvm-1b9a4ffd6bb2622360e6bae10bbcce7348186e94.zip
Still more P0202 constexpr-ifying. This batch is: for_each/for_each_n/lexicographical_compare
llvm-svn: 323147
Diffstat (limited to 'libcxx/test/std/algorithms/alg.sorting')
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp18
-rw-r--r--libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp19
2 files changed, 35 insertions, 2 deletions
diff --git a/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp
index 71dfeefe7e4..adec6aec801 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare.pass.cpp
@@ -12,14 +12,26 @@
// 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
// lexicographical_compare(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, 3};
+ int ib[] = {1, 3, 5, 2, 4, 6};
+
+ return std::lexicographical_compare(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib))
+ && !std::lexicographical_compare(std::begin(ib), std::end(ib), std::begin(ia), std::end(ia))
+ ;
+ }
+#endif
+
template <class Iter1, class Iter2>
void
test()
@@ -66,4 +78,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.lex.comparison/lexicographical_compare_comp.pass.cpp b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp
index c1851560ef2..f2800e055c5 100644
--- a/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.sorting/alg.lex.comparison/lexicographical_compare_comp.pass.cpp
@@ -12,7 +12,7 @@
// template<InputIterator Iter1, InputIterator Iter2, CopyConstructible 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
// lexicographical_compare(Iter1 first1, Iter1 last1,
// Iter2 first2, Iter2 last2, Compare comp);
@@ -20,8 +20,21 @@
#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, 3};
+ int ib[] = {1, 3, 5, 2, 4, 6};
+
+ std::greater<int> pred;
+ return !std::lexicographical_compare(std::begin(ia), std::end(ia), std::begin(ib), std::end(ib), pred)
+ && std::lexicographical_compare(std::begin(ib), std::end(ib), std::begin(ia), std::end(ia), pred)
+ ;
+ }
+#endif
+
template <class Iter1, class Iter2>
void
test()
@@ -70,4 +83,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
}
OpenPOWER on IntegriCloud