forked from boostorg/array
Add array_init_test.cpp
This commit is contained in:
@ -30,6 +30,7 @@ run array_hash.cpp
|
|||||||
|
|
||||||
run array_typedef_test.cpp ;
|
run array_typedef_test.cpp ;
|
||||||
run array_elems_test.cpp ;
|
run array_elems_test.cpp ;
|
||||||
|
run array_init_test.cpp ;
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
70
test/array_init_test.cpp
Normal file
70
test/array_init_test.cpp
Normal file
@ -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 <boost/array.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
template<class T, std::size_t N> void test1()
|
||||||
|
{
|
||||||
|
boost::array<T, N> a = {{}};
|
||||||
|
|
||||||
|
for( std::size_t i = 0; i < N; ++i )
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ( a[i], T() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T, std::size_t N> void test2()
|
||||||
|
{
|
||||||
|
boost::array<T, N> a = {};
|
||||||
|
|
||||||
|
for( std::size_t i = 0; i < N; ++i )
|
||||||
|
{
|
||||||
|
BOOST_TEST_EQ( a[i], T() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> void test3()
|
||||||
|
{
|
||||||
|
boost::array<T, 4> a = {{ 1, 2, 3, 4 }};
|
||||||
|
T b[ 4 ] = { 1, 2, 3, 4 };
|
||||||
|
|
||||||
|
BOOST_TEST_ALL_EQ( a.begin(), a.end(), b + 0, b + 4 );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T> void test4()
|
||||||
|
{
|
||||||
|
boost::array<T, 4> a = { 1, 2, 3, 4 };
|
||||||
|
T b[ 4 ] = { 1, 2, 3, 4 };
|
||||||
|
|
||||||
|
BOOST_TEST_ALL_EQ( a.begin(), a.end(), b + 0, b + 4 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// test1<int, 0>();
|
||||||
|
test1<int, 1>();
|
||||||
|
test1<int, 7>();
|
||||||
|
|
||||||
|
// test1<int const, 0>();
|
||||||
|
test1<int const, 1>();
|
||||||
|
test1<int const, 7>();
|
||||||
|
|
||||||
|
test2<int, 0>();
|
||||||
|
test2<int, 1>();
|
||||||
|
test2<int, 7>();
|
||||||
|
|
||||||
|
// test2<int const, 0>();
|
||||||
|
test2<int const, 1>();
|
||||||
|
test2<int const, 7>();
|
||||||
|
|
||||||
|
test3<int>();
|
||||||
|
test3<int const>();
|
||||||
|
|
||||||
|
test4<int>();
|
||||||
|
test4<int const>();
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user