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