From 9253e8f1af0aa1b99945859647e536a7c0739765 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 26 Jan 2025 05:41:56 +0200 Subject: [PATCH] Add array_fill_test_cx.cpp --- test/Jamfile.v2 | 1 + test/array_fill_test_cx.cpp | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 test/array_fill_test_cx.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 4236865..1f92809 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -59,6 +59,7 @@ compile array_get_test_cx.cpp ; # C++14 constexpr +compile array_fill_test_cx.cpp ; compile array_eq_test_cx.cpp ; compile array_lt_test_cx.cpp ; diff --git a/test/array_fill_test_cx.cpp b/test/array_fill_test_cx.cpp new file mode 100644 index 0000000..c0c8d97 --- /dev/null +++ b/test/array_fill_test_cx.cpp @@ -0,0 +1,51 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#if defined(BOOST_NO_CXX14_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined") + +#else + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +template constexpr boost::array filled( T const& v ) +{ + boost::array r = {}; + + r.fill( v ); + + return r; +} + +template void test1() +{ + constexpr boost::array a1 = filled( 7 ); + + STATIC_ASSERT( a1[0] == 7 ); + STATIC_ASSERT( a1[1] == 7 ); + STATIC_ASSERT( a1[2] == 7 ); + STATIC_ASSERT( a1[3] == 7 ); +} + +template void test2() +{ + constexpr boost::array a1 = filled( 7 ); + + (void)a1; +} + +int main() +{ + test1(); + test2(); +} + +#endif