Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/assign/test/static_list_of.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.3 KB
Line 
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(__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
17#endif
18
19#include <boost/assign/list_of.hpp>
20#include <boost/test/test_tools.hpp>
21#include <algorithm>
22#include <iostream>
23
24template< class Range >
25void print( const Range& r )
26{
27    std::cout << "\n printing " << typeid(r).name() << " \n"; 
28    std::cout << "\n";
29    for( typename Range::iterator i = r.begin(), e = r.end();
30         i !=e; ++i )
31         std::cout << " " << *i;
32}
33
34template< class Range >
35void sort( const Range& r )
36{
37    std::cout << "\n sorting " << typeid(r).name() << " \n"; 
38    std::sort( r.begin(), r.end() );
39    print( r );
40}
41
42template< class Range, class Pred >
43void sort( const Range& r, Pred pred )
44{
45    std::cout << "\n sorting " << typeid(r).name() << " \n"; 
46    std::sort( r.begin(), r.end(), pred );
47    print( r );
48}
49
50template< class Range >
51typename Range::const_iterator max_element( const Range& r )
52{
53    return std::max_element( r.begin(), r.end() );
54}
55
56
57
58void check_static_list_of()
59{
60    using namespace boost::assign;
61   
62    BOOST_CHECK( cref_list_of<5>( 1 )( 2 )( 3 )( 4 ).size() == 4 );
63   
64    int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7;
65
66    int& max = *max_element( ref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) );
67    BOOST_CHECK_EQUAL( max, f );
68    max = 8;
69    BOOST_CHECK_EQUAL( f, 8 );
70    const int& const_max = *max_element( cref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) );
71    BOOST_CHECK_EQUAL( max, const_max );
72
73    print( ref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) );
74    print( cref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) );
75
76    //
77    //print( cref_list_of<5>( "foo" )( "bar" )( "foobar" ) );
78    //
79}
80
81#include <boost/test/unit_test.hpp>
82using boost::unit_test::test_suite;
83
84test_suite* init_unit_test_suite( int argc, char* argv[] )
85{
86    test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
87
88    test->add( BOOST_TEST_CASE( &check_static_list_of ) );
89
90    return test;
91}
92
93
Note: See TracBrowser for help on using the repository browser.