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(); +}