From 63f8f022e229370cefcc3e08d97c3b086502a6ff Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 11 Jan 2025 21:29:33 +0200 Subject: [PATCH] Add array_c_array_test.cpp --- test/Jamfile.v2 | 1 + test/array_c_array_test.cpp | 70 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/array_c_array_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 0d629fb..f498852 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -38,6 +38,7 @@ run array_iterator_test.cpp ; run array_reverse_test.cpp ; run array_size_test.cpp ; run array_access_test.cpp ; +run array_c_array_test.cpp ; # diff --git a/test/array_c_array_test.cpp b/test/array_c_array_test.cpp new file mode 100644 index 0000000..b65d444 --- /dev/null +++ b/test/array_c_array_test.cpp @@ -0,0 +1,70 @@ +// 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 + +// c_array and get_c_array are nonstandard extensions +// probably need to be deprecated and removed + +template void test() +{ + boost::array a = {}; + + T* p1 = a.c_array(); + T* p2 = a.data(); + + BOOST_TEST_EQ( p1, p2 ); +} + +template void test2() +{ + { + boost::array a = {{}}; + + T (&e1)[ N ] = boost::get_c_array( a ); + T (&e2)[ N ] = a.elems; + + BOOST_TEST_EQ( static_cast( e1 ), static_cast( e2 ) ); + } + { + boost::array const a = {{}}; + + T const (&e1)[ N ] = boost::get_c_array( a ); + T const (&e2)[ N ] = a.elems; + + BOOST_TEST_EQ( static_cast( e1 ), static_cast( e2 ) ); + } +} + +int main() +{ + test(); + test(); + test(); + + test(); + +#if BOOST_WORKAROUND(BOOST_MSVC, < 1910) || BOOST_WORKAROUND(BOOST_GCC, < 50000) + + // = {} doesn't work for const T + +#else + + test(); + test(); + +#endif + + test2(); + test2(); + + test2(); + test2(); + + return boost::report_errors(); +}