summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/algorithms/alg.modifying.operations
diff options
context:
space:
mode:
authorMarshall Clow <mclow.lists@gmail.com>2018-01-20 20:14:32 +0000
committerMarshall Clow <mclow.lists@gmail.com>2018-01-20 20:14:32 +0000
commit4bfb9313c1ede05d3d59571faace20cd810e1fb9 (patch)
tree0d3ab7d6bd8a9f75caf8a2e4efa608a352052f91 /libcxx/test/std/algorithms/alg.modifying.operations
parent52fa0e9300892bfe982b948136c91c512170200c (diff)
downloadbcm5719-llvm-4bfb9313c1ede05d3d59571faace20cd810e1fb9.tar.gz
bcm5719-llvm-4bfb9313c1ede05d3d59571faace20cd810e1fb9.zip
More P0202 constexpr work. This commit adds fill/fill_n/generate/generate_n/unique/unique_copy. I removed a specialization of fill_n that recognized when we were dealing with raw pointers and 1 byte trivially-assignable types and did a memset, because the compiler will do that optimization for us.
llvm-svn: 323050
Diffstat (limited to 'libcxx/test/std/algorithms/alg.modifying.operations')
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp18
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp20
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp22
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp24
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp19
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp21
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp22
-rw-r--r--libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp19
8 files changed, 155 insertions, 10 deletions
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp
index c72adac9e2e..8b9e109d7be 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp
@@ -11,14 +11,26 @@
// template<ForwardIterator Iter, class T>
// requires OutputIterator<Iter, const T&>
-// void
+// constexpr void // constexpr after C++17
// fill(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[] = {0, 1, 2, 3, 4};
+
+ std::fill(std::begin(ia), std::end(ia), 5);
+
+ return std::all_of(std::begin(ia), std::end(ia), [](int a) {return a == 5; })
+ ;
+ }
+#endif
+
template <class Iter>
void
test_char()
@@ -56,4 +68,8 @@ int main()
test_int<bidirectional_iterator<int*> >();
test_int<random_access_iterator<int*> >();
test_int<int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
index f39436048ae..fea7165af7b 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp
@@ -11,15 +11,29 @@
// template<class Iter, IntegralLike Size, class T>
// requires OutputIterator<Iter, const T&>
-// OutputIterator
+// constexpr OutputIterator // constexpr after C++17
// fill_n(Iter first, Size n, const T& value);
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
#include "user_defined_integral.hpp"
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ const size_t N = 5;
+ int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N
+
+ auto it = std::fill_n(std::begin(ib), N, 5);
+ return it == (std::begin(ib) + N)
+ && std::all_of(std::begin(ib), it, [](int a) {return a == 5; })
+ && *it == 0 // don't overwrite the last value in the output array
+ ;
+ }
+#endif
+
typedef UserDefinedIntegral<unsigned> UDI;
template <class Iter>
@@ -153,4 +167,8 @@ int main()
test5();
test6();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp
index f166d67ba2f..8be501c273b 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp
@@ -12,19 +12,33 @@
// template<ForwardIterator Iter, Callable Generator>
// requires OutputIterator<Iter, Generator::result_type>
// && CopyConstructible<Generator>
-// void
+// constexpr void // constexpr after c++17
// generate(Iter first, Iter last, Generator gen);
#include <algorithm>
#include <cassert>
+#include "test_macros.h"
#include "test_iterators.h"
struct gen_test
{
- int operator()() const {return 1;}
+ TEST_CONSTEXPR int operator()() const {return 1;}
};
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {0, 1, 2, 3, 4};
+
+ std::generate(std::begin(ia), std::end(ia), gen_test());
+
+ return std::all_of(std::begin(ia), std::end(ia), [](int x) { return x == 1; })
+ ;
+ }
+#endif
+
+
template <class Iter>
void
test()
@@ -44,4 +58,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.generate/generate_n.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
index b7322542931..98b7bea653c 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
@@ -12,7 +12,7 @@
// template<class Iter, IntegralLike Size, Callable Generator>
// requires OutputIterator<Iter, Generator::result_type>
// && CopyConstructible<Generator>
-// void
+// constexpr void // constexpr after c++17
// generate_n(Iter first, Size n, Generator gen);
#ifdef _MSC_VER
@@ -28,9 +28,25 @@
struct gen_test
{
- int operator()() const {return 2;}
+ TEST_CONSTEXPR int operator()() const {return 2;}
};
+
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ const size_t N = 5;
+ int ib[] = {0, 0, 0, 0, 0, 0}; // one bigger than N
+
+ auto it = std::generate_n(std::begin(ib), N, gen_test());
+
+ return it == (std::begin(ib) + N)
+ && std::all_of(std::begin(ib), it, [](int x) { return x == 2; })
+ && *it == 0 // don't overwrite the last value in the output array
+ ;
+ }
+#endif
+
+
template <class Iter, class Size>
void
test2()
@@ -64,4 +80,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.unique/unique.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp
index 049ccfe9871..1c25b480858 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp
@@ -12,7 +12,7 @@
// template<ForwardIterator Iter>
// requires OutputIterator<Iter, Iter::reference>
// && EqualityComparable<Iter::value_type>
-// Iter
+// constexpr Iter // constexpr after C++17
// unique(Iter first, Iter last);
#include <algorithm>
@@ -22,6 +22,19 @@
#include "test_macros.h"
#include "test_iterators.h"
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {0, 1, 1, 3, 4};
+ const int expected[] = {0, 1, 3, 4};
+ const size_t N = 4;
+
+ auto it = std::unique(std::begin(ia), std::end(ia));
+ return it == (std::begin(ia) + N)
+ && std::equal(std::begin(ia), it, std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
template <class Iter>
void
test()
@@ -182,4 +195,8 @@ int main()
test1<random_access_iterator<Ptr*> >();
test1<Ptr*>();
#endif
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp
index 761dad4ecd0..48ddcf921e4 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp
@@ -14,14 +14,29 @@
// && EqualityComparable<InIter::value_type>
// && HasAssign<InIter::value_type, InIter::reference>
// && Constructible<InIter::value_type, InIter::reference>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// unique_copy(InIter first, InIter last, OutIter result);
#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, 4};
+ int ib[] = {0, 0, 0, 0, 0};
+ const int expected[] = {0, 1, 2, 4};
+
+ auto it = std::unique_copy(std::begin(ia), std::end(ia), std::begin(ib));
+ return it == (std::begin(ib) + std::size(expected))
+ && *it == 0 // don't overwrite final value in output
+ && std::equal(std::begin(ib), it, std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
template <class InIter, class OutIter>
void
test()
@@ -122,4 +137,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.unique/unique_copy_pred.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp
index 6819899a114..55bfd36d570 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp
@@ -15,14 +15,30 @@
// && HasAssign<InIter::value_type, InIter::reference>
// && Constructible<InIter::value_type, InIter::reference>
// && CopyConstructible<Pred>
-// OutIter
+// constexpr OutIter // constexpr after C++17
// unique_copy(InIter first, InIter last, OutIter result, Pred pred);
#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, 4};
+ int ib[] = {0, 0, 0, 0, 0};
+ const int expected[] = {0, 1, 2, 4};
+
+ auto it = std::unique_copy(std::begin(ia), std::end(ia), std::begin(ib),
+ [](int a, int b) {return a == b; });
+ return it == (std::begin(ib) + std::size(expected))
+ && *it == 0 // don't overwrite final value in output
+ && std::equal(std::begin(ib), it, std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
struct count_equal
{
static unsigned count;
@@ -149,4 +165,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.unique/unique_pred.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp
index 1640052058c..539d226e812 100644
--- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp
+++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp
@@ -12,7 +12,7 @@
// template<ForwardIterator Iter, EquivalenceRelation<auto, Iter::value_type> Pred>
// requires OutputIterator<Iter, RvalueOf<Iter::reference>::type>
// && CopyConstructible<Pred>
-// Iter
+// constexpr Iter // constexpr after C++17
// unique(Iter first, Iter last, Pred pred);
#include <algorithm>
@@ -22,6 +22,19 @@
#include "test_macros.h"
#include "test_iterators.h"
+#if TEST_STD_VER > 17
+TEST_CONSTEXPR bool test_constexpr() {
+ int ia[] = {0, 1, 1, 3, 4};
+ const int expected[] = {0, 1, 3, 4};
+ const size_t N = 4;
+
+ auto it = std::unique(std::begin(ia), std::end(ia), [](int a, int b) {return a == b; });
+ return it == (std::begin(ia) + N)
+ && std::equal(std::begin(ia), it, std::begin(expected), std::end(expected))
+ ;
+ }
+#endif
+
struct count_equal
{
static unsigned count;
@@ -224,4 +237,8 @@ int main()
test1<random_access_iterator<Ptr*> >();
test1<Ptr*>();
#endif
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}
OpenPOWER on IntegriCloud