|
| 1 | +// Copyright 2025 Peter Dimov |
| 2 | +// Distributed under the Boost Software License, Version 1.0. |
| 3 | +// https://www.boost.org/LICENSE_1_0.txt) |
| 4 | + |
| 5 | +#include <boost/array.hpp> |
| 6 | +#include <boost/config.hpp> |
| 7 | +#include <boost/config/pragma_message.hpp> |
| 8 | +#include <boost/config/workaround.hpp> |
| 9 | +#include <cstddef> |
| 10 | + |
| 11 | +#if defined(BOOST_NO_CXX14_CONSTEXPR) |
| 12 | + |
| 13 | +BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined") |
| 14 | + |
| 15 | +#else |
| 16 | + |
| 17 | +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) |
| 18 | + |
| 19 | +template<class T, std::size_t N> constexpr boost::array<T, N> assigned( boost::array<T, N> const& a1 ) |
| 20 | +{ |
| 21 | + boost::array<T, N> a2 = {}; |
| 22 | + |
| 23 | + a2 = a1; |
| 24 | + |
| 25 | + return a2; |
| 26 | +} |
| 27 | + |
| 28 | +template<class T> void test1() |
| 29 | +{ |
| 30 | + constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }}; |
| 31 | + constexpr boost::array<T, 4> a2 = assigned( a1 ); |
| 32 | + |
| 33 | + STATIC_ASSERT( a1[0] == a2[0] ); |
| 34 | + STATIC_ASSERT( a1[1] == a2[1] ); |
| 35 | + STATIC_ASSERT( a1[2] == a2[2] ); |
| 36 | + STATIC_ASSERT( a1[3] == a2[3] ); |
| 37 | +} |
| 38 | + |
| 39 | +template<class T> void test2() |
| 40 | +{ |
| 41 | + constexpr boost::array<T, 0> a1 = {}; |
| 42 | + constexpr boost::array<T, 0> a2 = assigned( a1 ); |
| 43 | + |
| 44 | + (void)a1; |
| 45 | + (void)a2; |
| 46 | +} |
| 47 | + |
| 48 | +int main() |
| 49 | +{ |
| 50 | + test1<int>(); |
| 51 | + test2<int>(); |
| 52 | +} |
| 53 | + |
| 54 | +#endif |
0 commit comments