summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/test/std/algorithms')
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp18
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp21
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end.pass.cpp26
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp28
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp26
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp27
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp17
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp22
-rw-r--r--libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp21
9 files changed, 192 insertions, 14 deletions
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp
index ee030925d55..8de06ec7b4b 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find.pass.cpp
@@ -11,14 +11,26 @@
// template<ForwardIterator Iter>
// requires EqualityComparable<Iter::value_type>
-// Iter
+// constexpr Iter // constexpr after C++17
// adjacent_find(Iter first, Iter last);
#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, 2, 0, 1, 2, 3};
+ int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
+
+ return (std::adjacent_find(std::begin(ia), std::end(ia)) == ia+2)
+ && (std::adjacent_find(std::begin(ib), std::end(ib)) == std::end(ib))
+ ;
+ }
+#endif
+
int main()
{
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
@@ -32,4 +44,8 @@ int main()
assert(std::adjacent_find(forward_iterator<const int*>(ia+3),
forward_iterator<const int*>(ia + sa)) ==
forward_iterator<const int*>(ia+sa));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp
index 4d172ff8139..bf445c54d15 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.adjacent.find/adjacent_find_pred.pass.cpp
@@ -11,15 +11,30 @@
// template<ForwardIterator Iter, EquivalenceRelation<auto, Iter::value_type> Pred>
// requires CopyConstructible<Pred>
-// Iter
+// constexpr Iter // constexpr after C++17
// adjacent_find(Iter first, Iter last, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool eq (int a, int b) { return a == b; }
+
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
+ int ib[] = {0, 1, 2, 7, 0, 1, 2, 3};
+
+ return (std::adjacent_find(std::begin(ia), std::end(ia), eq) == ia+2)
+ && (std::adjacent_find(std::begin(ib), std::end(ib), eq) == std::end(ib))
+ ;
+ }
+#endif
+
int main()
{
int ia[] = {0, 1, 2, 2, 0, 1, 2, 3};
@@ -36,4 +51,8 @@ int main()
forward_iterator<const int*>(ia + sa),
std::equal_to<int>()) ==
forward_iterator<const int*>(ia+sa));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
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
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp
index 966207671fc..bd929749004 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of.pass.cpp
@@ -11,14 +11,34 @@
// template<InputIterator Iter1, ForwardIterator Iter2>
// requires HasEqualTo<Iter1::value_type, Iter2::value_type>
-// Iter1
+// constexpr Iter1 // constexpr after C++17
// find_first_of(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[] = {7, 8, 9};
+ int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
+ typedef forward_iterator<int*> FI;
+ typedef bidirectional_iterator<int*> BI;
+ typedef random_access_iterator<int*> RI;
+
+ return (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia))) == FI(ic+1))
+ && (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib))) == FI(std::end(ic)))
+ && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia))) == BI(ic+1))
+ && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib))) == BI(std::end(ic)))
+ && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia))) == RI(ic+1))
+ && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib))) == RI(std::end(ic)))
+ ;
+ }
+#endif
+
int main()
{
int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
@@ -46,4 +66,8 @@ int main()
forward_iterator<const int*>(ic),
forward_iterator<const int*>(ic+1)) ==
input_iterator<const int*>(ia));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
index d1d954ca0ca..ea75e937eb7 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
@@ -12,15 +12,36 @@
// template<InputIterator Iter1, ForwardIterator Iter2,
// Predicate<auto, Iter1::value_type, Iter2::value_type> Pred>
// requires CopyConstructible<Pred>
-// Iter1
+// constexpr Iter1 // constexpr after C++17
// find_first_of(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2, Pred pred);
#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, 3};
+ int ib[] = {7, 8, 9};
+ int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
+ typedef forward_iterator<int*> FI;
+ typedef bidirectional_iterator<int*> BI;
+ typedef random_access_iterator<int*> RI;
+ std::equal_to<int> eq;
+
+ return (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ia)), FI(std::end(ia)), eq) == FI(ic+1))
+ && (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), FI(std::begin(ib)), FI(std::end(ib)), eq) == FI(std::end(ic)))
+ && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ia)), BI(std::end(ia)), eq) == BI(ic+1))
+ && (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), BI(std::begin(ib)), BI(std::end(ib)), eq) == BI(std::end(ic)))
+ && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ia)), RI(std::end(ia)), eq) == RI(ic+1))
+ && (std::find_first_of(RI(std::begin(ic)), RI(std::end(ic)), RI(std::begin(ib)), RI(std::end(ib)), eq) == RI(std::end(ic)))
+ ;
+ }
+#endif
+
int main()
{
int ia[] = {0, 1, 2, 3, 0, 1, 2, 3};
@@ -52,4 +73,8 @@ int main()
forward_iterator<const int*>(ic+1),
std::equal_to<int>()) ==
input_iterator<const int*>(ia));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
index 09f0f41215c..faff926d3d6 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find.pass.cpp
@@ -11,14 +11,25 @@
// template<InputIterator Iter, class T>
// requires HasEqualTo<Iter::value_type, T>
-// Iter
+// constexpr Iter // constexpr after C++17
// find(Iter first, Iter last, const T& value);
#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, 3, 5, 2, 4, 6};
+ int ib[] = {1, 2, 3, 4, 5, 6};
+ return (std::find(std::begin(ia), std::end(ia), 5) == ia+2)
+ && (std::find(std::begin(ib), std::end(ib), 9) == ib+6)
+ ;
+ }
+#endif
+
int main()
{
int ia[] = {0, 1, 2, 3, 4, 5};
@@ -28,4 +39,8 @@ int main()
assert(*r == 3);
r = std::find(input_iterator<const int*>(ia), input_iterator<const int*>(ia+s), 10);
assert(r == input_iterator<const int*>(ia+s));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp
index fa1faf17e0f..0fe084c01b5 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp
@@ -11,21 +11,33 @@
// template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
// requires CopyConstructible<Pred>
-// Iter
+// constexpr Iter // constexpr after C++17
// find_if(Iter first, Iter last, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
struct eq {
- eq (int val) : v(val) {}
- bool operator () (int v2) const { return v == v2; }
+ TEST_CONSTEXPR eq (int val) : v(val) {}
+ TEST_CONSTEXPR bool operator () (int v2) const { return v == v2; }
int v;
};
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 4, 6};
+ int ib[] = {1, 2, 3, 7, 5, 6};
+ eq c(4);
+ return (std::find_if(std::begin(ia), std::end(ia), c) == ia+4)
+ && (std::find_if(std::begin(ib), std::end(ib), c) == ib+6)
+ ;
+ }
+#endif
+
int main()
{
int ia[] = {0, 1, 2, 3, 4, 5};
@@ -38,4 +50,8 @@ int main()
input_iterator<const int*>(ia+s),
eq(10));
assert(r == input_iterator<const int*>(ia+s));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp
index 1f3c34b2144..971a94dce2e 100644
--- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp
@@ -11,21 +11,32 @@
// template<InputIterator Iter, Predicate<auto, Iter::value_type> Pred>
// requires CopyConstructible<Pred>
-// Iter
+// constexpr Iter // constexpr after C++17
// find_if_not(Iter first, Iter last, Pred pred);
#include <algorithm>
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
struct ne {
- ne (int val) : v(val) {}
- bool operator () (int v2) const { return v != v2; }
+ TEST_CONSTEXPR ne (int val) : v(val) {}
+ TEST_CONSTEXPR bool operator () (int v2) const { return v != v2; }
int v;
};
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {1, 3, 5, 2, 4, 6};
+ int ib[] = {1, 2, 3, 7, 5, 6};
+ ne c(4);
+ return (std::find_if_not(std::begin(ia), std::end(ia), c) == ia+4)
+ && (std::find_if_not(std::begin(ib), std::end(ib), c) == ib+6)
+ ;
+ }
+#endif
int main()
{
@@ -39,4 +50,8 @@ int main()
input_iterator<const int*>(ia+s),
ne(10));
assert(r == input_iterator<const int*>(ia+s));
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
OpenPOWER on IntegriCloud