summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2018-01-19 18:07:29 +0000
committerMarshall Clow <mclow.lists@gmail.com>2018-01-19 18:07:29 +0000
commit12c7423ff9de4a8931309714e583c03b595b88f9 (patch)
tree549991b90d2e5dd767214f2bb38bf932402de7bb /libcxx/test/std/algorithms/alg.modifying.operations/alg.replace
parent969a432b187f80bbc0a8b6547ba8192c830da5fb (diff)
downloadbcm5719-llvm-12c7423ff9de4a8931309714e583c03b595b88f9.tar.gz
bcm5719-llvm-12c7423ff9de4a8931309714e583c03b595b88f9.zip
More P0202 constexpr-ifying in <algorithm>. This commit handles replace/replace_if/replace_copy/replace_copy_if.
llvm-svn: 322975
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations/alg.replace')
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp19
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp23
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp25
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp21
4 files changed, 82 insertions, 6 deletions
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp
index f6033351ffc..56a744b2c9d 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace.pass.cpp
@@ -13,14 +13,27 @@
// requires OutputIterator<Iter, Iter::reference>
// && OutputIterator<Iter, const T&>
// && HasEqualTo<Iter::value_type, T>
-// void
+// constexpr void // constexpr after C++17
// replace(Iter first, Iter last, const T& old_value, const T& new_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[] = {0, 1, 2, 3, 4};
+ const int expected[] = {0, 1, 5, 3, 4};
+
+ std::replace(std::begin(ia), std::end(ia), 2, 5);
+ return std::equal(std::begin(ia), std::end(ia), std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
template <class Iter>
void
test()
@@ -41,4 +54,8 @@ int main()
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp
index 3c4d0e50817..aad7f9f921d 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy.pass.cpp
@@ -13,15 +13,32 @@
// requires OutputIterator<OutIter, InIter::reference>
// && OutputIterator<OutIter, const T&>
// && HasEqualTo<InIter::value_type, T>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// replace_copy(InIter first, InIter last, OutIter result, const T& old_value,
// const T& new_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[] = {0, 1, 2, 3, 4};
+ int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger
+ const int expected[] = {0, 1, 5, 3, 4};
+
+ auto it = std::replace_copy(std::begin(ia), std::end(ia), std::begin(ib), 2, 5);
+
+ return it == (std::begin(ib) + std::size(ia))
+ && *it == 0 // don't overwrite the last value in the output array
+ && std::equal(std::begin(ib), it, std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
template <class InIter, class OutIter>
void
test()
@@ -69,4 +86,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp
index f2ffece12e8..6ba74ff07bd 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_copy_if.pass.cpp
@@ -14,16 +14,33 @@
// requires OutputIterator<OutIter, InIter::reference>
// && OutputIterator<OutIter, const T&>
// && CopyConstructible<Pred>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// replace_copy_if(InIter first, InIter last, OutIter result, Pred pred, const T& new_value);
#include <algorithm>
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
-bool equalToTwo(int v) { return v == 2; }
+TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
+
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {0, 1, 2, 3, 4};
+ int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger
+ const int expected[] = {0, 1, 5, 3, 4};
+
+ auto it = std::replace_copy_if(std::begin(ia), std::end(ia), std::begin(ib), equalToTwo, 5);
+
+ return it == (std::begin(ib) + std::size(ia))
+ && *it == 0 // don't overwrite the last value in the output array
+ && std::equal(std::begin(ib), it, std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
template <class InIter, class OutIter>
void
@@ -73,4 +90,8 @@ int main()
test<const int*, bidirectional_iterator<int*> >();
test<const int*, random_access_iterator<int*> >();
test<const int*, int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp
index ebb2945d7c4..eeff4068740 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.replace/replace_if.pass.cpp
@@ -13,16 +13,29 @@
// requires OutputIterator<Iter, Iter::reference>
// && OutputIterator<Iter, const T&>
// && CopyConstructible<Pred>
-// void
+// constexpr void // constexpr after C++17
// replace_if(Iter first, Iter last, Pred pred, const T& new_value);
#include <algorithm>
#include <functional>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
-bool equalToTwo(int v) { return v == 2; }
+TEST_CONSTEXPR bool equalToTwo(int v) { return v == 2; }
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {0, 1, 2, 3, 4};
+ const int expected[] = {0, 1, 5, 3, 4};
+
+ std::replace_if(std::begin(ia), std::end(ia), equalToTwo, 5);
+ return std::equal(std::begin(ia), std::end(ia), std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
template <class Iter>
void
@@ -44,4 +57,8 @@ int main()
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
OpenPOWER on IntegriCloud