|
| 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_CXX11_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> void test1() |
| 20 | +{ |
| 21 | + constexpr boost::array<T, 1> a = {{}}; |
| 22 | + |
| 23 | + STATIC_ASSERT( a[0] == 0 ); |
| 24 | +} |
| 25 | + |
| 26 | +template<class T> void test2() |
| 27 | +{ |
| 28 | + constexpr boost::array<T, 2> a = {}; |
| 29 | + |
| 30 | + STATIC_ASSERT( a[0] == 0 ); |
| 31 | + STATIC_ASSERT( a[1] == 0 ); |
| 32 | +} |
| 33 | + |
| 34 | +template<class T> void test3() |
| 35 | +{ |
| 36 | + constexpr boost::array<T, 3> a = {{ 1, 2, 3 }}; |
| 37 | + |
| 38 | + STATIC_ASSERT( a[0] == 1 ); |
| 39 | + STATIC_ASSERT( a[1] == 2 ); |
| 40 | + STATIC_ASSERT( a[2] == 3 ); |
| 41 | +} |
| 42 | + |
| 43 | +template<class T> void test4() |
| 44 | +{ |
| 45 | + constexpr boost::array<T, 4> a = { 1, 2, 3, 4 }; |
| 46 | + |
| 47 | + STATIC_ASSERT( a[0] == 1 ); |
| 48 | + STATIC_ASSERT( a[1] == 2 ); |
| 49 | + STATIC_ASSERT( a[2] == 3 ); |
| 50 | + STATIC_ASSERT( a[3] == 4 ); |
| 51 | +} |
| 52 | + |
| 53 | +template<class T> void test5() |
| 54 | +{ |
| 55 | + // constexpr boost::array<T, 0> a = {{}}; |
| 56 | +} |
| 57 | + |
| 58 | +template<class T> void test6() |
| 59 | +{ |
| 60 | + constexpr boost::array<T, 0> a = {}; |
| 61 | + (void)a; |
| 62 | +} |
| 63 | + |
| 64 | +int main() |
| 65 | +{ |
| 66 | + test1<int>(); |
| 67 | + test2<int>(); |
| 68 | + test3<int>(); |
| 69 | + test4<int>(); |
| 70 | + test5<int>(); |
| 71 | + test6<int>(); |
| 72 | +} |
| 73 | + |
| 74 | +#endif |
0 commit comments