diff options
Diffstat (limited to 'libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp')
-rw-r--r-- | libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp index d6fdd18968d..a334c609333 100644 --- a/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp +++ b/libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/test.pass.cpp @@ -11,14 +11,26 @@ // template<InputIterator Iter, Callable<auto, Iter::reference> Function> // requires CopyConstructible<Function> -// Function +// constexpr Function // constexpr after C++17 // for_each(Iter first, Iter last, Function f); #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, 6, 7}; + int expected[] = {3, 5, 8, 9}; + + std::for_each(std::begin(ia), std::end(ia), [](int &a) { a += 2; }); + return std::equal(std::begin(ia), std::end(ia), std::begin(expected)) + ; + } +#endif + struct for_each_test { for_each_test(int c) : count(c) {} @@ -36,4 +48,8 @@ int main() assert(f.count == s); for (unsigned i = 0; i < s; ++i) assert(ia[i] == static_cast<int>(i+1)); + +#if TEST_STD_VER > 17 + static_assert(test_constexpr()); +#endif } |