From cbd8e1a8dcf43aeb0294086e2116a9e8d8cacdb3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 11 Jan 2025 21:56:12 +0200 Subject: [PATCH] Add array_assign_test.cpp --- test/Jamfile.v2 | 1 + test/array_assign_test.cpp | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 test/array_assign_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 21d6cf4..c7c14bf 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -40,6 +40,7 @@ run array_size_test.cpp ; run array_access_test.cpp ; run array_c_array_test.cpp ; run array_fill_test.cpp ; +run array_assign_test.cpp ; # diff --git a/test/array_assign_test.cpp b/test/array_assign_test.cpp new file mode 100644 index 0000000..91c9b16 --- /dev/null +++ b/test/array_assign_test.cpp @@ -0,0 +1,60 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +// assign is a nonstandard equivalent of fill +// it probably needs to be deprecated and removed + +template void test() +{ + boost::array a = {}; + + a.assign( 1 ); + + for( std::size_t i = 0; i < N; ++i ) + { + BOOST_TEST_EQ( a[i], 1 ); + } +} + +template void test2() +{ + boost::array a = {{ 1, 2, 3, 4 }}; + + a.assign( 5 ); + + for( std::size_t i = 0; i < 4; ++i ) + { + BOOST_TEST_EQ( a[i], 5 ); + } +} + +template void test3() +{ + boost::array a = {{ 1, 2, 3, 4 }}; + + // aliasing + a.assign( a[ 1 ] ); + + for( std::size_t i = 0; i < 4; ++i ) + { + BOOST_TEST_EQ( a[i], 2 ); + } +} + +int main() +{ + test(); + test(); + test(); + + test2(); + + test3(); + + return boost::report_errors(); +}