From 54d839c8bc1d41d141be2825b7d5d1cef147f436 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 25 Jan 2025 19:23:50 +0200 Subject: [PATCH] Add array_size_test_cx.cpp --- test/Jamfile.v2 | 1 + test/array_size_test_cx.cpp | 64 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/array_size_test_cx.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 551e8e7c..f982ec25 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -50,6 +50,7 @@ run array_get_test.cpp ; # compile array_init_test_cx.cpp ; +compile array_size_test_cx.cpp ; # diff --git a/test/array_size_test_cx.cpp b/test/array_size_test_cx.cpp new file mode 100644 index 00000000..bfa4f40f --- /dev/null +++ b/test/array_size_test_cx.cpp @@ -0,0 +1,64 @@ +// 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_CXX11_CONSTEXPR) + +BOOST_PRAGMA_MESSAGE("Test skipped because BOOST_NO_CXX11_CONSTEXPR is defined") + +#else + +#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) + +template void test1() +{ + constexpr boost::array a = {}; + + STATIC_ASSERT( a.size() == N ); + STATIC_ASSERT( a.empty() == (N == 0) ); + STATIC_ASSERT( a.max_size() == N ); +} + +template void test2() +{ + typedef boost::array A; + + STATIC_ASSERT( A().size() == N ); + STATIC_ASSERT( A().empty() == (N == 0) ); + STATIC_ASSERT( A().max_size() == N ); +} + +// the functions are static, which deviates from the standard +template void test3() +{ + typedef boost::array A; + + STATIC_ASSERT( A::size() == N ); + STATIC_ASSERT( A::empty() == (N == 0) ); + STATIC_ASSERT( A::max_size() == N ); + + STATIC_ASSERT( A::static_size == N ); +} + +int main() +{ + test1(); + test1(); + test1(); + + test2(); + test2(); + test2(); + + test3(); + test3(); + test3(); +} + +#endif