Skip to content

Commit 54d839c

Browse files
committed
Add array_size_test_cx.cpp
1 parent e766343 commit 54d839c

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ run array_get_test.cpp ;
5050
#
5151

5252
compile array_init_test_cx.cpp ;
53+
compile array_size_test_cx.cpp ;
5354

5455
#
5556

test/array_size_test_cx.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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, std::size_t N> void test1()
20+
{
21+
constexpr boost::array<T, N> a = {};
22+
23+
STATIC_ASSERT( a.size() == N );
24+
STATIC_ASSERT( a.empty() == (N == 0) );
25+
STATIC_ASSERT( a.max_size() == N );
26+
}
27+
28+
template<class T, std::size_t N> void test2()
29+
{
30+
typedef boost::array<T, N> A;
31+
32+
STATIC_ASSERT( A().size() == N );
33+
STATIC_ASSERT( A().empty() == (N == 0) );
34+
STATIC_ASSERT( A().max_size() == N );
35+
}
36+
37+
// the functions are static, which deviates from the standard
38+
template<class T, std::size_t N> void test3()
39+
{
40+
typedef boost::array<T, N> A;
41+
42+
STATIC_ASSERT( A::size() == N );
43+
STATIC_ASSERT( A::empty() == (N == 0) );
44+
STATIC_ASSERT( A::max_size() == N );
45+
46+
STATIC_ASSERT( A::static_size == N );
47+
}
48+
49+
int main()
50+
{
51+
test1<int, 0>();
52+
test1<int, 1>();
53+
test1<int, 7>();
54+
55+
test2<int, 0>();
56+
test2<int, 1>();
57+
test2<int, 7>();
58+
59+
test3<int, 0>();
60+
test3<int, 1>();
61+
test3<int, 7>();
62+
}
63+
64+
#endif

0 commit comments

Comments
 (0)