|
| 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(__cpp_impl_three_way_comparison) |
| 12 | + |
| 13 | +BOOST_PRAGMA_MESSAGE( "Test skipped because __cpp_impl_three_way_comparison is not defined" ) |
| 14 | +int main() {} |
| 15 | + |
| 16 | +#elif !( __cpp_impl_three_way_comparison >= 201907L ) |
| 17 | + |
| 18 | +BOOST_PRAGMA_MESSAGE( "Test skipped because __cpp_impl_three_way_comparison is defined to " BOOST_STRINGIZE(__cpp_impl_three_way_comparison) ) |
| 19 | +int main() {} |
| 20 | + |
| 21 | +#else |
| 22 | + |
| 23 | +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) |
| 24 | + |
| 25 | +template<class T, std::size_t N> void test1() |
| 26 | +{ |
| 27 | + constexpr auto eq = 0 <=> 0; |
| 28 | + |
| 29 | + constexpr boost::array<T, N> a1 = {}; |
| 30 | + constexpr boost::array<T, N> a2 = {}; |
| 31 | + |
| 32 | + STATIC_ASSERT( ( a1 <=> a2 ) == eq ); |
| 33 | +} |
| 34 | + |
| 35 | +template<class T> void test2() |
| 36 | +{ |
| 37 | + constexpr auto eq = 0 <=> 0; |
| 38 | + constexpr auto lt = 0 <=> 1; |
| 39 | + constexpr auto gt = 1 <=> 0; |
| 40 | + |
| 41 | + { |
| 42 | + constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }}; |
| 43 | + constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 4 }}; |
| 44 | + |
| 45 | + STATIC_ASSERT( ( a1 <=> a2 ) == eq ); |
| 46 | + } |
| 47 | + { |
| 48 | + constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }}; |
| 49 | + constexpr boost::array<T, 4> a2 = {{ 1, 2, 3, 5 }}; |
| 50 | + |
| 51 | + STATIC_ASSERT( ( a1 <=> a2 ) == lt ); |
| 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 ) == gt ); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +int main() |
| 62 | +{ |
| 63 | + test1<int, 0>(); |
| 64 | + test1<int, 1>(); |
| 65 | + test1<int, 7>(); |
| 66 | + |
| 67 | + test2<int>(); |
| 68 | +} |
| 69 | + |
| 70 | +#endif |
0 commit comments