Files
array/test/array_size_test.cpp

78 lines
1.6 KiB
C++
Raw Permalink Normal View History

2025-01-11 04:13:41 +02:00
// Copyright 2025 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
2025-02-23 21:04:28 +02:00
// https://www.boost.org/LICENSE_1_0.txt
2025-01-11 04:13:41 +02:00
#include <boost/array.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iterator>
#include <cstddef>
template<class T, std::size_t N> void test1()
{
{
boost::array<T, N> a = {{}};
BOOST_TEST_EQ( a.size(), N );
BOOST_TEST_EQ( a.empty(), N == 0 );
BOOST_TEST_EQ( a.max_size(), N );
(void)a; // msvc-12.0
2025-01-11 04:13:41 +02:00
}
{
boost::array<T, N> const a = {{}};
BOOST_TEST_EQ( a.size(), N );
BOOST_TEST_EQ( a.empty(), N == 0 );
BOOST_TEST_EQ( a.max_size(), N );
(void)a; // msvc-12.0
2025-01-11 04:13:41 +02:00
}
}
template<class T, std::size_t N> void test2()
{
typedef boost::array<T, N> A;
BOOST_TEST_EQ( A().size(), N );
BOOST_TEST_EQ( A().empty(), N == 0 );
BOOST_TEST_EQ( A().max_size(), N );
}
// the functions are static, which deviates from the standard
template<class T, std::size_t N> void test3()
{
typedef boost::array<T, N> A;
BOOST_TEST_EQ( A::size(), N );
BOOST_TEST_EQ( A::empty(), N == 0 );
BOOST_TEST_EQ( A::max_size(), N );
BOOST_TEST_EQ( A::static_size, N );
}
int main()
{
2025-01-26 21:26:46 +02:00
test1<int, 0>();
2025-01-11 04:13:41 +02:00
test1<int, 1>();
test1<int, 7>();
2025-01-26 21:26:46 +02:00
test1<int const, 0>();
2025-01-11 04:13:41 +02:00
test1<int const, 1>();
test1<int const, 7>();
test2<int, 0>();
test2<int, 1>();
test2<int, 7>();
test3<int, 0>();
test3<int, 1>();
test3<int, 7>();
test3<int const, 0>();
test3<int const, 1>();
test3<int const, 7>();
return boost::report_errors();
}