1 /* tests for using class array<> specialization for size 0
2 * (C) Copyright Alisdair Meredith 2006.
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/array.hpp>
12 #define BOOST_TEST_MAIN
13 #include <boost/test/unit_test.hpp>
18 void BadValue( const T & )
20 BOOST_CHECK ( false );
26 typedef boost::array< T, 0 > test_type;
28 // Test value and aggegrate initialization
29 test_type test_case = {};
30 const boost::array< T, 0 > const_test_case = test_type();
32 test_case.fill ( T() );
34 // front/back and operator[] must compile, but calling them is undefined
35 // Likewise, all tests below should evaluate to false, avoiding undefined behaviour
36 BOOST_CHECK ( test_case.empty());
37 BOOST_CHECK ( const_test_case.empty());
39 BOOST_CHECK ( test_case.size() == 0 );
40 BOOST_CHECK ( const_test_case.size() == 0 );
42 // Assert requirements of TR1 6.2.2.4
43 BOOST_CHECK ( test_case.begin() == test_case.end());
44 BOOST_CHECK ( test_case.cbegin() == test_case.cend());
45 BOOST_CHECK ( const_test_case.begin() == const_test_case.end());
46 BOOST_CHECK ( const_test_case.cbegin() == const_test_case.cend());
48 BOOST_CHECK ( test_case.begin() != const_test_case.begin() );
49 if( test_case.data() == const_test_case.data() ) {
50 // Value of data is unspecified in TR1, so no requirement this test pass or fail
51 // However, it must compile!
54 // Check can safely use all iterator types with std algorithms
55 std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
56 std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
57 std::for_each( test_case.cbegin(), test_case.cend(), BadValue< T > );
58 std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
59 std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
60 std::for_each( const_test_case.cbegin(), const_test_case.cend(), BadValue< T > );
62 // Check swap is well formed
63 std::swap( test_case, test_case );
65 // Check assignment operator and overloads are well formed
66 test_case = const_test_case;
68 // Confirm at() throws the std lib defined exception
70 BadValue( test_case.at( 0 ));
71 } catch ( const std::out_of_range & ) {
75 BadValue( const_test_case.at( 0 ) );
76 } catch ( const std::out_of_range & ) {
82 BOOST_AUTO_TEST_CASE( test_main )
86 RunTests< long double >();
87 RunTests< std::string >();