1// Boost.Range 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/range/
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/range/rbegin.hpp>
20#include <boost/range/rend.hpp>
21#include <boost/range/begin.hpp>
22#include <boost/range/end.hpp>
23#include <boost/static_assert.hpp>
24#include <boost/type_traits.hpp>
25#include <boost/test/test_tools.hpp>
26#include <boost/test/unit_test.hpp>
27#include <vector>
28#include <algorithm>
29
30void check_iterator()
31{
32 typedef std::vector<int> vec_t;
33 typedef vec_t::iterator iterator;
34 typedef std::pair<iterator,iterator> pair_t;
35 typedef boost::range_reverse_iterator<pair_t>::type rev_iterator;
36 typedef std::pair<rev_iterator,rev_iterator> rev_pair_t;
37
38 vec_t vec;
39 pair_t p = std::make_pair( x: vec.begin(), y: vec.end() );
40 rev_pair_t rp = std::make_pair( x: boost::rbegin( c&: p ), y: boost::rend( c&: p ) );
41 int a[] = {1,2,3,4,5,6,7,8,9,10};
42 const int ca[] = {1,2,3,4,5,6,7,8,9,10,11,12};
43 BOOST_CHECK( boost::rbegin( vec ) == boost::range_reverse_iterator<vec_t>::type( vec.end() ) );
44 BOOST_CHECK( boost::rend( vec ) == boost::range_reverse_iterator<vec_t>::type( vec.begin() ) );
45 BOOST_CHECK( std::distance( boost::rbegin( vec ), boost::rend( vec ) ) == std::distance( boost::begin( vec ), boost::end( vec ) ) );
46
47 BOOST_CHECK( boost::rbegin( p ) == boost::begin( rp ) );
48 BOOST_CHECK( boost::rend( p ) == boost::end( rp ) );
49 BOOST_CHECK( std::distance( boost::rbegin( p ), boost::rend( p ) ) == std::distance( boost::begin( rp ), boost::end( rp ) ) );
50 BOOST_CHECK( std::distance( boost::begin( p ), boost::end( p ) ) == std::distance( boost::rbegin( rp ), boost::rend( rp ) ) );
51
52
53 BOOST_CHECK_EQUAL( &*boost::begin( a ), &*( boost::rend( a ) - 1 ) );
54 BOOST_CHECK_EQUAL( &*( boost::end( a ) - 1 ), &*boost::rbegin( a ) );
55 BOOST_CHECK_EQUAL( &*boost::begin( ca ), &*( boost::rend( ca ) - 1 ) );
56 BOOST_CHECK_EQUAL( &*( boost::end( ca ) - 1 ), &*boost::rbegin( ca ) );
57}
58
59
60boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
61{
62 boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
63
64 test->add( BOOST_TEST_CASE( &check_iterator ) );
65
66 return test;
67}
68
69
70
71
72
73
74
75

source code of boost/libs/range/test/reversible_range.cpp