]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/assign/test/array.cpp
1 // Boost.Assign library
3 // Copyright Thorsten Ottosen 2003-2004. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // For more information, see http://www.boost.org/libs/assign/
11 #include <boost/detail/workaround.hpp>
13 #if BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x564) )
14 # pragma warn -8091 // suppress warning in Boost.Test
15 # pragma warn -8057 // unused argument argc/argv in Boost.Test
18 #include <boost/assign/list_of.hpp>
19 #include <boost/array.hpp>
20 #include <boost/test/test_tools.hpp>
25 #ifndef BOOST_NO_CXX11_HDR_ARRAY
28 void check_std_array()
30 using namespace boost::assign
;
32 typedef std::array
<float,6> Array
;
34 Array a
= list_of(1)(2)(3)(4)(5)(6);
36 BOOST_CHECK_EQUAL( a
[0], 1 );
37 BOOST_CHECK_EQUAL( a
[5], 6 );
38 // last element is implicitly 0
39 Array a2
= list_of(1)(2)(3)(4)(5);
40 BOOST_CHECK_EQUAL( a2
[5], 0 );
41 // two last elements are implicitly
42 a2
= list_of(1)(2)(3)(4);
43 BOOST_CHECK_EQUAL( a2
[4], 0 );
44 BOOST_CHECK_EQUAL( a2
[5], 0 );
46 BOOST_CHECK_THROW( a2
= list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception
);
53 using namespace boost::assign
;
55 typedef boost::array
<float,6> Array
;
58 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
59 Array a
= list_of(1)(2)(3)(4)(5)(6).to_array(a
);
61 Array a
= list_of(1)(2)(3)(4)(5)(6);
64 BOOST_CHECK_EQUAL( a
[0], 1 );
65 BOOST_CHECK_EQUAL( a
[5], 6 );
66 // last element is implicitly 0
67 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
68 Array a2
= list_of(1)(2)(3)(4)(5).to_array(a2
);
70 Array a2
= list_of(1)(2)(3)(4)(5);
72 BOOST_CHECK_EQUAL( a2
[5], 0 );
73 // two last elements are implicitly
74 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
75 a2
= list_of(1))(2)(3)(4).to_array(a2
);
77 a2
= list_of(1)(2)(3)(4);
79 BOOST_CHECK_EQUAL( a2
[4], 0 );
80 BOOST_CHECK_EQUAL( a2
[5], 0 );
82 #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
84 BOOST_CHECK_THROW( a2
= list_of(1)(2)(3)(4)(5)(6)(6).to_array(a2
),
85 assignment_exception
);
87 BOOST_CHECK_THROW( a2
= list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception
);
92 #include <boost/test/unit_test.hpp>
93 using boost::unit_test::test_suite
;
96 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
98 test_suite
* test
= BOOST_TEST_SUITE( "List Test Suite" );
100 test
->add( BOOST_TEST_CASE( &check_array
) );
101 #ifndef BOOST_NO_CXX11_HDR_ARRAY
102 test
->add( BOOST_TEST_CASE( &check_std_array
) );