Chris@16
|
1 // Copyright Neil Groves 2010. Use, modification and
|
Chris@16
|
2 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 //
|
Chris@16
|
6 //
|
Chris@16
|
7 // For more information, see http://www.boost.org/libs/range/
|
Chris@16
|
8 //
|
Chris@16
|
9 #ifndef BOOST_RANGE_ANY_RANGE_HPP_INCLUDED
|
Chris@16
|
10 #define BOOST_RANGE_ANY_RANGE_HPP_INCLUDED
|
Chris@16
|
11
|
Chris@16
|
12 #include <boost/config.hpp>
|
Chris@16
|
13 #include <boost/iterator/iterator_categories.hpp>
|
Chris@16
|
14 #include <boost/iterator/iterator_traits.hpp>
|
Chris@16
|
15 #include <boost/iterator/iterator_facade.hpp>
|
Chris@16
|
16 #include <boost/iterator/iterator_adaptor.hpp>
|
Chris@16
|
17 #include <boost/range/detail/any_iterator.hpp>
|
Chris@16
|
18 #include <boost/range/concepts.hpp>
|
Chris@16
|
19 #include <boost/range/reference.hpp>
|
Chris@16
|
20 #include <boost/range/value_type.hpp>
|
Chris@16
|
21 #include <boost/range/iterator_range_core.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 namespace boost
|
Chris@16
|
24 {
|
Chris@16
|
25 namespace range_detail
|
Chris@16
|
26 {
|
Chris@16
|
27 // If T is use_default, return the result of Default, otherwise
|
Chris@16
|
28 // return T.
|
Chris@16
|
29 //
|
Chris@16
|
30 // This is an implementation artifact used to pick intelligent default
|
Chris@16
|
31 // values when the user specified boost::use_default as a template
|
Chris@16
|
32 // parameter.
|
Chris@16
|
33 template<
|
Chris@16
|
34 class T,
|
Chris@16
|
35 class Default
|
Chris@16
|
36 >
|
Chris@16
|
37 struct any_range_default_help
|
Chris@16
|
38 : mpl::eval_if<
|
Chris@16
|
39 is_same<T, use_default>
|
Chris@16
|
40 , Default
|
Chris@16
|
41 , mpl::identity<T>
|
Chris@16
|
42 >
|
Chris@16
|
43 {
|
Chris@16
|
44 };
|
Chris@16
|
45
|
Chris@16
|
46 template<
|
Chris@16
|
47 class WrappedRange
|
Chris@16
|
48 , class Value
|
Chris@16
|
49 , class Reference
|
Chris@16
|
50 >
|
Chris@16
|
51 struct any_range_value_type
|
Chris@16
|
52 {
|
Chris@16
|
53 # ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY
|
Chris@16
|
54 typedef typename any_range_default_help<
|
Chris@16
|
55 Value
|
Chris@16
|
56 , mpl::eval_if<
|
Chris@16
|
57 is_same<Reference, use_default>
|
Chris@16
|
58 , range_value<
|
Chris@16
|
59 typename remove_const<WrappedRange>
|
Chris@16
|
60 ::type>
|
Chris@16
|
61 , remove_reference<Reference>
|
Chris@16
|
62 >
|
Chris@16
|
63 >::type type;
|
Chris@16
|
64 # else
|
Chris@16
|
65 typedef typename any_range_default_help<
|
Chris@16
|
66 Value
|
Chris@16
|
67 , range_value<
|
Chris@16
|
68 typename remove_const<WrappedRange>
|
Chris@16
|
69 ::type>
|
Chris@16
|
70 >::type type;
|
Chris@16
|
71 # endif
|
Chris@16
|
72 };
|
Chris@16
|
73
|
Chris@16
|
74 template<
|
Chris@16
|
75 class Value
|
Chris@16
|
76 , class Traversal
|
Chris@101
|
77 , class Reference = Value&
|
Chris@101
|
78 , class Difference = std::ptrdiff_t
|
Chris@16
|
79 , class Buffer = use_default
|
Chris@16
|
80 >
|
Chris@16
|
81 class any_range
|
Chris@16
|
82 : public iterator_range<
|
Chris@16
|
83 any_iterator<
|
Chris@16
|
84 Value
|
Chris@16
|
85 , Traversal
|
Chris@16
|
86 , Reference
|
Chris@16
|
87 , Difference
|
Chris@16
|
88 , typename any_range_default_help<
|
Chris@16
|
89 Buffer
|
Chris@16
|
90 , mpl::identity<any_iterator_default_buffer>
|
Chris@16
|
91 >::type
|
Chris@16
|
92 >
|
Chris@16
|
93 >
|
Chris@16
|
94 {
|
Chris@16
|
95 typedef iterator_range<
|
Chris@16
|
96 any_iterator<
|
Chris@16
|
97 Value
|
Chris@16
|
98 , Traversal
|
Chris@16
|
99 , Reference
|
Chris@16
|
100 , Difference
|
Chris@16
|
101 , typename any_range_default_help<
|
Chris@16
|
102 Buffer
|
Chris@16
|
103 , mpl::identity<any_iterator_default_buffer>
|
Chris@16
|
104 >::type
|
Chris@16
|
105 >
|
Chris@16
|
106 > base_type;
|
Chris@16
|
107
|
Chris@16
|
108 struct enabler {};
|
Chris@16
|
109 struct disabler {};
|
Chris@16
|
110 public:
|
Chris@16
|
111 any_range()
|
Chris@16
|
112 {
|
Chris@16
|
113 }
|
Chris@16
|
114
|
Chris@16
|
115 any_range(const any_range& other)
|
Chris@16
|
116 : base_type(other)
|
Chris@16
|
117 {
|
Chris@16
|
118 }
|
Chris@16
|
119
|
Chris@16
|
120 template<class WrappedRange>
|
Chris@16
|
121 any_range(WrappedRange& wrapped_range)
|
Chris@16
|
122 : base_type(boost::begin(wrapped_range),
|
Chris@16
|
123 boost::end(wrapped_range))
|
Chris@16
|
124 {
|
Chris@16
|
125 }
|
Chris@16
|
126
|
Chris@16
|
127 template<class WrappedRange>
|
Chris@16
|
128 any_range(const WrappedRange& wrapped_range)
|
Chris@16
|
129 : base_type(boost::begin(wrapped_range),
|
Chris@16
|
130 boost::end(wrapped_range))
|
Chris@16
|
131 {
|
Chris@16
|
132 }
|
Chris@16
|
133
|
Chris@16
|
134 template<
|
Chris@16
|
135 class OtherValue
|
Chris@16
|
136 , class OtherTraversal
|
Chris@16
|
137 , class OtherReference
|
Chris@16
|
138 , class OtherDifference
|
Chris@16
|
139 >
|
Chris@16
|
140 any_range(const any_range<
|
Chris@16
|
141 OtherValue
|
Chris@16
|
142 , OtherTraversal
|
Chris@16
|
143 , OtherReference
|
Chris@16
|
144 , OtherDifference
|
Chris@16
|
145 , Buffer
|
Chris@16
|
146 >& other)
|
Chris@16
|
147 : base_type(boost::begin(other), boost::end(other))
|
Chris@16
|
148 {
|
Chris@16
|
149 }
|
Chris@16
|
150
|
Chris@16
|
151 template<class Iterator>
|
Chris@16
|
152 any_range(Iterator first, Iterator last)
|
Chris@16
|
153 : base_type(first, last)
|
Chris@16
|
154 {
|
Chris@16
|
155 }
|
Chris@16
|
156 };
|
Chris@16
|
157
|
Chris@16
|
158 template<
|
Chris@16
|
159 class WrappedRange
|
Chris@16
|
160 , class Value = use_default
|
Chris@16
|
161 , class Traversal = use_default
|
Chris@16
|
162 , class Reference = use_default
|
Chris@16
|
163 , class Difference = use_default
|
Chris@16
|
164 , class Buffer = use_default
|
Chris@16
|
165 >
|
Chris@16
|
166 struct any_range_type_generator
|
Chris@16
|
167 {
|
Chris@16
|
168 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<WrappedRange> ));
|
Chris@16
|
169 typedef any_range<
|
Chris@16
|
170 typename any_range_value_type<
|
Chris@16
|
171 WrappedRange
|
Chris@16
|
172 , Value
|
Chris@16
|
173 , typename any_range_default_help<
|
Chris@16
|
174 Reference
|
Chris@16
|
175 , range_reference<WrappedRange>
|
Chris@16
|
176 >::type
|
Chris@16
|
177 >::type
|
Chris@16
|
178 , typename any_range_default_help<
|
Chris@16
|
179 Traversal
|
Chris@16
|
180 , iterator_traversal<
|
Chris@16
|
181 typename range_iterator<WrappedRange>::type
|
Chris@16
|
182 >
|
Chris@16
|
183 >::type
|
Chris@16
|
184 , typename any_range_default_help<
|
Chris@16
|
185 Reference
|
Chris@16
|
186 , range_reference<WrappedRange>
|
Chris@16
|
187 >::type
|
Chris@16
|
188 , typename any_range_default_help<
|
Chris@16
|
189 Difference
|
Chris@16
|
190 , range_difference<WrappedRange>
|
Chris@16
|
191 >::type
|
Chris@16
|
192 , typename any_range_default_help<
|
Chris@16
|
193 Buffer
|
Chris@16
|
194 , mpl::identity<any_iterator_default_buffer>
|
Chris@16
|
195 >::type
|
Chris@16
|
196 > type;
|
Chris@16
|
197 };
|
Chris@16
|
198 } // namespace range_detail
|
Chris@16
|
199
|
Chris@16
|
200 using range_detail::any_range;
|
Chris@16
|
201 using range_detail::any_range_type_generator;
|
Chris@16
|
202 } // namespace boost
|
Chris@16
|
203
|
Chris@16
|
204 #endif // include guard
|