summaryrefslogtreecommitdiff
path: root/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp')
-rw-r--r--test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp b/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
index b7322542931d1..7e81610acc831 100644
--- a/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
+++ b/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
@@ -12,25 +12,42 @@
// 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
+#include "test_macros.h"
+
+#ifdef TEST_COMPILER_C1XX
#pragma warning(disable: 4244) // conversion from 'const double' to 'int', possible loss of data
#endif
#include <algorithm>
#include <cassert>
-#include "test_macros.h"
#include "test_iterators.h"
#include "user_defined_integral.hpp"
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 +81,8 @@ int main()
test<bidirectional_iterator<int*> >();
test<random_access_iterator<int*> >();
test<int*>();
+
+#if TEST_STD_VER > 17
+ static_assert(test_constexpr());
+#endif
}