]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/assign/test/static_list_of.cpp
6e989d35efb6e232c6a1cff2335a414b6295cf12
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/
12 #include <boost/detail/workaround.hpp>
14 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
15 # pragma warn -8091 // supress warning in Boost.Test
16 # pragma warn -8057 // unused argument argc/argv in Boost.Test
19 #include <boost/assign/list_of.hpp>
20 #include <boost/array.hpp>
21 #include <boost/test/test_tools.hpp>
25 template< class Range
>
26 void print( const Range
& r
)
28 std::cout
<< "\n printing " << typeid(r
).name() << " \n";
30 for( typename
Range::iterator i
= r
.begin(), e
= r
.end();
32 std::cout
<< " " << *i
;
35 template< class Range
>
36 void sort( const Range
& r
)
38 std::cout
<< "\n sorting " << typeid(r
).name() << " \n";
39 std::sort( r
.begin(), r
.end() );
43 template< class Range
, class Pred
>
44 void sort( const Range
& r
, Pred pred
)
46 std::cout
<< "\n sorting " << typeid(r
).name() << " \n";
47 std::sort( r
.begin(), r
.end(), pred
);
51 template< class Range
>
52 typename
Range::const_iterator
max_element( const Range
& r
)
54 return std::max_element( r
.begin(), r
.end() );
59 void check_static_list_of()
61 using namespace boost::assign
;
63 BOOST_CHECK( cref_list_of
<5>( 1 )( 2 )( 3 )( 4 ).size() == 4 );
65 int a
=1,b
=5,c
=3,d
=4,e
=2,f
=9,g
=0,h
=7;
67 int& max
= *max_element( ref_list_of
<8>(a
)(b
)(c
)(d
)(e
)(f
)(g
)(h
) );
68 BOOST_CHECK_EQUAL( max
, f
);
70 BOOST_CHECK_EQUAL( f
, 8 );
71 const int& const_max
= *max_element( cref_list_of
<8>(a
)(b
)(c
)(d
)(e
)(f
)(g
)(h
) );
72 BOOST_CHECK_EQUAL( max
, const_max
);
74 print( ref_list_of
<8>(a
)(b
)(c
)(d
)(e
)(f
)(g
)(h
) );
75 print( cref_list_of
<8>(a
)(b
)(c
)(d
)(e
)(f
)(g
)(h
) );
77 boost::array
<int,4> array
= cref_list_of
<4>(1)(2)(3)(4);
79 BOOST_CHECK_EQUAL( array
[0], 1 );
80 BOOST_CHECK_EQUAL( array
[3], 4 );
82 //print( cref_list_of<5>( "foo" )( "bar" )( "foobar" ) );
86 #include <boost/test/unit_test.hpp>
87 using boost::unit_test::test_suite
;
89 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
91 test_suite
* test
= BOOST_TEST_SUITE( "List Test Suite" );
93 test
->add( BOOST_TEST_CASE( &check_static_list_of
) );