• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <boost/detail/workaround.hpp>
12 
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
16 #endif
17 
18 #include <boost/range/concepts.hpp>
19 #include <boost/range/functions.hpp>
20 #include <boost/range/metafunctions.hpp>
21 #include <boost/static_assert.hpp>
22 #include <boost/type_traits.hpp>
23 #include <boost/test/test_tools.hpp>
24 #include <vector>
25 #include <iterator>
26 #include <utility>
27 
check_iterator_pair()28 void check_iterator_pair()
29 {
30     typedef std::vector<int> vec_t;
31     vec_t                    vec;
32     vec.push_back( 4 );
33     typedef std::pair<vec_t::iterator,vec_t::iterator>
34                              pair_t;
35     typedef std::pair<vec_t::const_iterator,vec_t::const_iterator>
36                              const_pair_t;
37     typedef const pair_t     const_pair_tt;
38     pair_t                   pair       = std::make_pair( boost::begin( vec ), boost::end( vec ) );
39     const_pair_t             const_pair = std::make_pair( boost::begin( vec ), boost::end( vec ) );
40     const_pair_tt            constness_pair( pair );
41 
42 
43     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_value<pair_t>::type,
44                           std::iterator_traits<pair_t::first_type>::value_type>::value ));
45     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator<pair_t>::type, pair_t::first_type >::value ));
46     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_const_iterator<pair_t>::type, pair_t::first_type >::value ));
47     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_difference<pair_t>::type,
48                           std::iterator_traits<pair_t::first_type>::difference_type >::value ));
49     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_size<pair_t>::type, std::size_t >::value ));
50     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator<pair_t>::type, pair_t::first_type >::value ));
51     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator<const_pair_t>::type, const_pair_t::first_type >::value ));
52 
53     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_value<const_pair_tt>::type,
54                           std::iterator_traits<const_pair_t::first_type>::value_type>::value ));
55     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value ));
56     //
57     // This behavior is not supported with v2.
58     //BOOST_STATIC_ASSERT(( is_same< range_const_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value ));
59     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_difference<const_pair_tt>::type,
60                           std::iterator_traits<const_pair_tt::first_type>::difference_type >::value ));
61     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_size<const_pair_tt>::type, std::size_t >::value ));
62     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value ));
63     BOOST_STATIC_ASSERT(( boost::is_same< boost::range_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value ));
64 
65     BOOST_CHECK( boost::begin( pair ) == pair.first );
66     BOOST_CHECK( boost::end( pair )   == pair.second );
67     BOOST_CHECK( boost::empty( pair ) == (pair.first == pair.second) );
68     BOOST_CHECK( boost::size( pair )  ==
69                     static_cast<std::size_t>(
70                         std::distance(pair.first, pair.second)) );
71 
72     BOOST_CHECK( boost::begin( const_pair ) == const_pair.first );
73     BOOST_CHECK( boost::end( const_pair )   == const_pair.second );
74     BOOST_CHECK( boost::empty( const_pair ) == (const_pair.first == const_pair.second) );
75     BOOST_CHECK( boost::size( const_pair )  ==
76                     static_cast<std::size_t>(
77                         std::distance(const_pair.first, const_pair.second)) );
78 
79     BOOST_CHECK( boost::begin( constness_pair ) == constness_pair.first );
80     BOOST_CHECK( boost::end( constness_pair )   == constness_pair.second );
81     BOOST_CHECK( boost::empty( constness_pair ) == (constness_pair.first == const_pair.second) );
82     BOOST_CHECK( boost::size( constness_pair )  ==
83                     static_cast<std::size_t>(
84                         std::distance(constness_pair.first,
85                                       constness_pair.second)) );
86 }
87 
88 
89 #include <boost/test/unit_test.hpp>
90 
init_unit_test_suite(int argc,char * argv[])91 boost::unit_test::test_suite* init_unit_test_suite( int argc, char* argv[] )
92 {
93     boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
94 
95     test->add( BOOST_TEST_CASE( &check_iterator_pair ) );
96 
97     return test;
98 }
99 
100 
101 
102 
103 
104 
105