Skip to content

Commit 324827c

Browse files
committed
Add array_assign_test_cx.cpp
1 parent 9253e8f commit 324827c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ compile array_get_test_cx.cpp ;
5959

6060
# C++14 constexpr
6161

62+
compile array_assign_test_cx.cpp ;
6263
compile array_fill_test_cx.cpp ;
6364
compile array_eq_test_cx.cpp ;
6465
compile array_lt_test_cx.cpp ;

test/array_assign_test_cx.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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_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> constexpr boost::array<T, N> assigned( boost::array<T, N> const& a1 )
20+
{
21+
boost::array<T, N> a2 = {};
22+
23+
a2 = a1;
24+
25+
return a2;
26+
}
27+
28+
template<class T> void test1()
29+
{
30+
constexpr boost::array<T, 4> a1 = {{ 1, 2, 3, 4 }};
31+
constexpr boost::array<T, 4> a2 = assigned( a1 );
32+
33+
STATIC_ASSERT( a1[0] == a2[0] );
34+
STATIC_ASSERT( a1[1] == a2[1] );
35+
STATIC_ASSERT( a1[2] == a2[2] );
36+
STATIC_ASSERT( a1[3] == a2[3] );
37+
}
38+
39+
template<class T> void test2()
40+
{
41+
constexpr boost::array<T, 0> a1 = {};
42+
constexpr boost::array<T, 0> a2 = assigned( a1 );
43+
44+
(void)a1;
45+
(void)a2;
46+
}
47+
48+
int main()
49+
{
50+
test1<int>();
51+
test2<int>();
52+
}
53+
54+
#endif

0 commit comments

Comments
 (0)