1// Boost.Assign library
2//
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)
7//
8// For more information, see http://www.boost.org/libs/assign/
9//
10
11
12#include <boost/detail/workaround.hpp>
13
14#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
15# pragma warn -8091 // suppress warning in Boost.Test
16# pragma warn -8057 // unused argument argc/argv in Boost.Test
17#endif
18
19#include <boost/assign/list_of.hpp>
20#include <boost/array.hpp>
21#include <boost/test/test_tools.hpp>
22#include <algorithm>
23#include <iostream>
24
25template< class Range >
26void print( const Range& r )
27{
28 std::cout << "\n printing " << typeid(r).name() << " \n";
29 std::cout << "\n";
30 for( typename Range::iterator i = r.begin(), e = r.end();
31 i !=e; ++i )
32 std::cout << " " << *i;
33}
34
35template< class Range >
36void sort( const Range& r )
37{
38 std::cout << "\n sorting " << typeid(r).name() << " \n";
39 std::sort( r.begin(), r.end() );
40 print( r );
41}
42
43template< class Range, class Pred >
44void sort( const Range& r, Pred pred )
45{
46 std::cout << "\n sorting " << typeid(r).name() << " \n";
47 std::sort( r.begin(), r.end(), pred );
48 print( r );
49}
50
51template< class Range >
52typename Range::const_iterator max_element( const Range& r )
53{
54 return std::max_element( r.begin(), r.end() );
55}
56
57
58
59void check_static_list_of()
60{
61 using namespace boost::assign;
62
63 BOOST_CHECK( cref_list_of<5>( 1 )( 2 )( 3 )( 4 ).size() == 4 );
64
65 int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7;
66
67 int& max = *max_element( r: ref_list_of<8>(t&: a)(b)(c)(d)(e)(f)(g)(h) );
68 BOOST_CHECK_EQUAL( max, f );
69 max = 8;
70 BOOST_CHECK_EQUAL( f, 8 );
71 const int& const_max = *max_element( r: cref_list_of<8>(t: a)(b)(c)(d)(e)(f)(g)(h) );
72 BOOST_CHECK_EQUAL( max, const_max );
73
74 print( r: ref_list_of<8>(t&: a)(b)(c)(d)(e)(f)(g)(h) );
75 print( r: cref_list_of<8>(t: a)(b)(c)(d)(e)(f)(g)(h) );
76
77 boost::array<int,4> array = cref_list_of<4>(t: 1)(2)(3)(4);
78
79 BOOST_CHECK_EQUAL( array[0], 1 );
80 BOOST_CHECK_EQUAL( array[3], 4 );
81 //
82 //print( cref_list_of<5>( "foo" )( "bar" )( "foobar" ) );
83 //
84}
85
86#include <boost/test/unit_test.hpp>
87using boost::unit_test::test_suite;
88
89test_suite* init_unit_test_suite( int argc, char* argv[] )
90{
91 test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
92
93 test->add( BOOST_TEST_CASE( &check_static_list_of ) );
94
95 return test;
96}
97
98
99

source code of boost/libs/assign/test/static_list_of.cpp