comparison DEPENDENCIES/generic/include/boost/range/sub_range.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 // Boost.Range library
2 //
3 // Copyright Neil Groves 2009.
4 // Copyright Thorsten Ottosen 2003-2004. Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // For more information, see http://www.boost.org/libs/range/
10 //
11
12 #ifndef BOOST_RANGE_SUB_RANGE_HPP
13 #define BOOST_RANGE_SUB_RANGE_HPP
14
15 #include <boost/detail/workaround.hpp>
16
17 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
18 #pragma warning( push )
19 #pragma warning( disable : 4996 )
20 #endif
21
22 #include <boost/range/config.hpp>
23 #include <boost/range/iterator_range.hpp>
24 #include <boost/range/value_type.hpp>
25 #include <boost/range/size_type.hpp>
26 #include <boost/range/difference_type.hpp>
27 #include <boost/range/algorithm/equal.hpp>
28 #include <boost/assert.hpp>
29 #include <boost/type_traits/is_reference.hpp>
30 #include <boost/type_traits/remove_reference.hpp>
31
32 namespace boost
33 {
34
35 template< class ForwardRange >
36 class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type >
37 {
38 typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator_t;
39 typedef iterator_range< iterator_t > base;
40
41 typedef BOOST_DEDUCED_TYPENAME base::impl impl;
42 public:
43 typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type value_type;
44 typedef BOOST_DEDUCED_TYPENAME range_iterator<ForwardRange>::type iterator;
45 typedef BOOST_DEDUCED_TYPENAME range_iterator<const ForwardRange>::type const_iterator;
46 typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type difference_type;
47 typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type size_type;
48 typedef BOOST_DEDUCED_TYPENAME base::reference reference;
49
50 public: // for return value of front/back
51 typedef BOOST_DEDUCED_TYPENAME
52 boost::mpl::if_< boost::is_reference<reference>,
53 const BOOST_DEDUCED_TYPENAME boost::remove_reference<reference>::type&,
54 reference >::type const_reference;
55
56 public:
57 sub_range() : base()
58 { }
59
60 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500) )
61 sub_range( const sub_range& r )
62 : base( static_cast<const base&>( r ) )
63 { }
64 #endif
65
66 template< class ForwardRange2 >
67 sub_range( ForwardRange2& r ) :
68
69 #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
70 base( impl::adl_begin( r ), impl::adl_end( r ) )
71 #else
72 base( r )
73 #endif
74 { }
75
76 template< class ForwardRange2 >
77 sub_range( const ForwardRange2& r ) :
78
79 #if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
80 base( impl::adl_begin( r ), impl::adl_end( r ) )
81 #else
82 base( r )
83 #endif
84 { }
85
86 template< class Iter >
87 sub_range( Iter first, Iter last ) :
88 base( first, last )
89 { }
90
91 template< class ForwardRange2 >
92 sub_range& operator=( ForwardRange2& r )
93 {
94 base::operator=( r );
95 return *this;
96 }
97
98 template< class ForwardRange2 >
99 sub_range& operator=( const ForwardRange2& r )
100 {
101 base::operator=( r );
102 return *this;
103 }
104
105 sub_range& operator=( const sub_range& r )
106 {
107 base::operator=( static_cast<const base&>(r) );
108 return *this;
109 }
110
111 public:
112
113 iterator begin() { return base::begin(); }
114 const_iterator begin() const { return base::begin(); }
115 iterator end() { return base::end(); }
116 const_iterator end() const { return base::end(); }
117 difference_type size() const { return base::size(); }
118
119
120 public: // convenience
121 reference front()
122 {
123 return base::front();
124 }
125
126 const_reference front() const
127 {
128 return base::front();
129 }
130
131 reference back()
132 {
133 return base::back();
134 }
135
136 const_reference back() const
137 {
138 return base::back();
139 }
140
141 reference operator[]( difference_type sz )
142 {
143 return base::operator[](sz);
144 }
145
146 const_reference operator[]( difference_type sz ) const
147 {
148 return base::operator[](sz);
149 }
150
151 };
152
153 template< class ForwardRange, class ForwardRange2 >
154 inline bool operator==( const sub_range<ForwardRange>& l,
155 const sub_range<ForwardRange2>& r )
156 {
157 return boost::equal( l, r );
158 }
159
160 template< class ForwardRange, class ForwardRange2 >
161 inline bool operator!=( const sub_range<ForwardRange>& l,
162 const sub_range<ForwardRange2>& r )
163 {
164 return !boost::equal( l, r );
165 }
166
167 template< class ForwardRange, class ForwardRange2 >
168 inline bool operator<( const sub_range<ForwardRange>& l,
169 const sub_range<ForwardRange2>& r )
170 {
171 return iterator_range_detail::less_than( l, r );
172 }
173
174
175 } // namespace 'boost'
176
177 #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500))
178 #pragma warning( pop )
179 #endif
180
181 #endif
182