diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f498852..21d6cf4 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -39,6 +39,7 @@ run array_reverse_test.cpp ; run array_size_test.cpp ; run array_access_test.cpp ; run array_c_array_test.cpp ; +run array_fill_test.cpp ; # diff --git a/test/array_fill_test.cpp b/test/array_fill_test.cpp new file mode 100644 index 0000000..17ca90f --- /dev/null +++ b/test/array_fill_test.cpp @@ -0,0 +1,57 @@ +// Copyright 2025 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include + +template void test() +{ + boost::array a = {}; + + a.fill( 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.fill( 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.fill( 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(); +}