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(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
---|
14 | # pragma warn -8091 // supress warning in Boost.Test |
---|
15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test |
---|
16 | #endif |
---|
17 | |
---|
18 | #include <boost/range/functions.hpp> |
---|
19 | #include <boost/range/metafunctions.hpp> |
---|
20 | #include <boost/static_assert.hpp> |
---|
21 | #include <boost/type_traits.hpp> |
---|
22 | #include <boost/test/test_tools.hpp> |
---|
23 | #include <vector> |
---|
24 | |
---|
25 | using namespace boost; |
---|
26 | |
---|
27 | void check_iterator_pair() |
---|
28 | { |
---|
29 | typedef std::vector<int> vec_t; |
---|
30 | vec_t vec; |
---|
31 | vec.push_back( 4 ); |
---|
32 | typedef std::pair<vec_t::iterator,vec_t::iterator> |
---|
33 | pair_t; |
---|
34 | typedef std::pair<vec_t::const_iterator,vec_t::const_iterator> |
---|
35 | const_pair_t; |
---|
36 | typedef const pair_t const_pair_tt; |
---|
37 | pair_t pair = std::make_pair( begin( vec ), end( vec ) ); |
---|
38 | const_pair_t const_pair = std::make_pair( begin( vec ), end( vec ) ); |
---|
39 | const_pair_tt constness_pair( pair ); |
---|
40 | |
---|
41 | |
---|
42 | BOOST_STATIC_ASSERT(( is_same< range_value<pair_t>::type, |
---|
43 | detail::iterator_traits<pair_t::first_type>::value_type>::value )); |
---|
44 | BOOST_STATIC_ASSERT(( is_same< range_iterator<pair_t>::type, pair_t::first_type >::value )); |
---|
45 | BOOST_STATIC_ASSERT(( is_same< range_const_iterator<pair_t>::type, pair_t::first_type >::value )); |
---|
46 | BOOST_STATIC_ASSERT(( is_same< range_difference<pair_t>::type, |
---|
47 | detail::iterator_traits<pair_t::first_type>::difference_type >::value )); |
---|
48 | BOOST_STATIC_ASSERT(( is_same< range_size<pair_t>::type, std::size_t >::value )); |
---|
49 | BOOST_STATIC_ASSERT(( is_same< range_result_iterator<pair_t>::type, pair_t::first_type >::value )); |
---|
50 | BOOST_STATIC_ASSERT(( is_same< range_result_iterator<const_pair_t>::type, const_pair_t::first_type >::value )); |
---|
51 | |
---|
52 | BOOST_STATIC_ASSERT(( is_same< range_value<const_pair_tt>::type, |
---|
53 | detail::iterator_traits<const_pair_t::first_type>::value_type>::value )); |
---|
54 | BOOST_STATIC_ASSERT(( is_same< range_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value )); |
---|
55 | BOOST_STATIC_ASSERT(( is_same< range_const_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value )); |
---|
56 | BOOST_STATIC_ASSERT(( is_same< range_difference<const_pair_tt>::type, |
---|
57 | detail::iterator_traits<const_pair_tt::first_type>::difference_type >::value )); |
---|
58 | BOOST_STATIC_ASSERT(( is_same< range_size<const_pair_tt>::type, std::size_t >::value )); |
---|
59 | BOOST_STATIC_ASSERT(( is_same< range_result_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value )); |
---|
60 | BOOST_STATIC_ASSERT(( is_same< range_result_iterator<const_pair_tt>::type, const_pair_tt::first_type >::value )); |
---|
61 | |
---|
62 | BOOST_CHECK( begin( pair ) == pair.first ); |
---|
63 | BOOST_CHECK( end( pair ) == pair.second ); |
---|
64 | BOOST_CHECK( empty( pair ) == (pair.first == pair.second) ); |
---|
65 | BOOST_CHECK( size( pair ) == std::size_t( std::distance( pair.first, pair.second ) ) ); |
---|
66 | |
---|
67 | BOOST_CHECK( begin( const_pair ) == const_pair.first ); |
---|
68 | BOOST_CHECK( end( const_pair ) == const_pair.second ); |
---|
69 | BOOST_CHECK( empty( const_pair ) == (const_pair.first == const_pair.second) ); |
---|
70 | BOOST_CHECK( size( const_pair ) == std::size_t( std::distance( const_pair.first, const_pair.second ) ) ); |
---|
71 | |
---|
72 | BOOST_CHECK( begin( constness_pair ) == constness_pair.first ); |
---|
73 | BOOST_CHECK( end( constness_pair ) == constness_pair.second ); |
---|
74 | BOOST_CHECK( empty( constness_pair ) == (constness_pair.first == const_pair.second) ); |
---|
75 | BOOST_CHECK( size( constness_pair ) == std::size_t( std::distance( constness_pair.first, constness_pair.second ) ) ); |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | #include <boost/test/unit_test.hpp> |
---|
81 | using boost::unit_test::test_suite; |
---|
82 | |
---|
83 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
---|
84 | { |
---|
85 | test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" ); |
---|
86 | |
---|
87 | test->add( BOOST_TEST_CASE( &check_iterator_pair ) ); |
---|
88 | |
---|
89 | return test; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|
96 | |
---|