| 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 | #ifndef BOOST_RANGE_SUB_RANGE_HPP |
|---|
| 12 | #define BOOST_RANGE_SUB_RANGE_HPP |
|---|
| 13 | |
|---|
| 14 | #include <boost/range/config.hpp> |
|---|
| 15 | #include <boost/range/iterator_range.hpp> |
|---|
| 16 | #include <boost/range/value_type.hpp> |
|---|
| 17 | #include <boost/range/result_iterator.hpp> |
|---|
| 18 | #include <boost/range/size_type.hpp> |
|---|
| 19 | #include <boost/range/difference_type.hpp> |
|---|
| 20 | #include <boost/assert.hpp> |
|---|
| 21 | |
|---|
| 22 | namespace boost |
|---|
| 23 | { |
|---|
| 24 | |
|---|
| 25 | template< class ForwardRange > |
|---|
| 26 | class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_result_iterator<ForwardRange>::type > |
|---|
| 27 | { |
|---|
| 28 | typedef BOOST_DEDUCED_TYPENAME range_result_iterator<ForwardRange>::type iterator_t; |
|---|
| 29 | typedef iterator_range< iterator_t > base; |
|---|
| 30 | |
|---|
| 31 | typedef BOOST_DEDUCED_TYPENAME base::impl impl; |
|---|
| 32 | public: |
|---|
| 33 | typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type; |
|---|
| 34 | typedef BOOST_DEDUCED_TYPENAME range_result_iterator<ForwardRange>::type iterator; |
|---|
| 35 | typedef BOOST_DEDUCED_TYPENAME range_const_iterator<ForwardRange>::type const_iterator; |
|---|
| 36 | typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type; |
|---|
| 37 | typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type; |
|---|
| 38 | |
|---|
| 39 | public: |
|---|
| 40 | sub_range() : base() |
|---|
| 41 | { } |
|---|
| 42 | /* |
|---|
| 43 | #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) |
|---|
| 44 | typedef sub_range<ForwardRange> this_type; |
|---|
| 45 | |
|---|
| 46 | sub_range( this_type r ) : |
|---|
| 47 | : base( r ) |
|---|
| 48 | { } |
|---|
| 49 | |
|---|
| 50 | this_type& operator=( this_type r ) |
|---|
| 51 | { |
|---|
| 52 | base::operator=( r ); |
|---|
| 53 | return *this; |
|---|
| 54 | } |
|---|
| 55 | #endif |
|---|
| 56 | */ |
|---|
| 57 | template< class ForwardRange2 > |
|---|
| 58 | sub_range( ForwardRange2& r ) : |
|---|
| 59 | |
|---|
| 60 | #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) |
|---|
| 61 | base( impl::adl_begin( r ), impl::adl_end( r ) ) |
|---|
| 62 | #else |
|---|
| 63 | base( r ) |
|---|
| 64 | #endif |
|---|
| 65 | { } |
|---|
| 66 | |
|---|
| 67 | template< class ForwardRange2 > |
|---|
| 68 | sub_range( const ForwardRange2& r ) : |
|---|
| 69 | |
|---|
| 70 | #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 ) |
|---|
| 71 | base( impl::adl_begin( r ), impl::adl_end( r ) ) |
|---|
| 72 | #else |
|---|
| 73 | base( r ) |
|---|
| 74 | #endif |
|---|
| 75 | { } |
|---|
| 76 | |
|---|
| 77 | template< class Iter > |
|---|
| 78 | sub_range( Iter first, Iter last ) : |
|---|
| 79 | base( first, last ) |
|---|
| 80 | { } |
|---|
| 81 | |
|---|
| 82 | template< class ForwardRange2 > |
|---|
| 83 | sub_range& operator=( ForwardRange2& r ) |
|---|
| 84 | { |
|---|
| 85 | base::operator=( r ); |
|---|
| 86 | return *this; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | template< class ForwardRange2 > |
|---|
| 90 | sub_range& operator=( const ForwardRange2& r ) |
|---|
| 91 | { |
|---|
| 92 | base::operator=( r ); |
|---|
| 93 | return *this; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | public: |
|---|
| 97 | |
|---|
| 98 | iterator begin() { return base::begin(); } |
|---|
| 99 | const_iterator begin() const { return base::begin(); } |
|---|
| 100 | iterator end() { return base::end(); } |
|---|
| 101 | const_iterator end() const { return base::end(); } |
|---|
| 102 | size_type size() const { return base::size(); } |
|---|
| 103 | |
|---|
| 104 | |
|---|
| 105 | public: // convenience |
|---|
| 106 | value_type& front() |
|---|
| 107 | { |
|---|
| 108 | return base::front(); |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | const value_type& front() const |
|---|
| 112 | { |
|---|
| 113 | return base::front(); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | value_type& back() |
|---|
| 117 | { |
|---|
| 118 | return base::back(); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | const value_type& back() const |
|---|
| 122 | { |
|---|
| 123 | return base::back(); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | value_type& operator[]( size_type sz ) |
|---|
| 127 | { |
|---|
| 128 | return base::operator[](sz); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | const value_type& operator[]( size_type sz ) const |
|---|
| 132 | { |
|---|
| 133 | return base::operator[](sz); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | }; |
|---|
| 137 | |
|---|
| 138 | template< class ForwardRange, class ForwardRange2 > |
|---|
| 139 | inline bool operator==( const sub_range<ForwardRange>& l, |
|---|
| 140 | const sub_range<ForwardRange2>& r ) |
|---|
| 141 | { |
|---|
| 142 | return iterator_range_detail::equal( l, r ); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | template< class ForwardRange, class ForwardRange2 > |
|---|
| 146 | inline bool operator!=( const sub_range<ForwardRange>& l, |
|---|
| 147 | const sub_range<ForwardRange2>& r ) |
|---|
| 148 | { |
|---|
| 149 | return !iterator_range_detail::equal( l, r ); |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | template< class ForwardRange, class ForwardRange2 > |
|---|
| 153 | inline bool operator<( const sub_range<ForwardRange>& l, |
|---|
| 154 | const sub_range<ForwardRange2>& r ) |
|---|
| 155 | { |
|---|
| 156 | return iterator_range_detail::less_than( l, r ); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | } // namespace 'boost' |
|---|
| 161 | |
|---|
| 162 | #endif |
|---|