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 #include <boost/cast.hpp>
|
Chris@16
|
23
|
Chris@16
|
24 namespace boost
|
Chris@16
|
25 {
|
Chris@16
|
26 namespace range_detail
|
Chris@16
|
27 {
|
Chris@16
|
28 // If T is use_default, return the result of Default, otherwise
|
Chris@16
|
29 // return T.
|
Chris@16
|
30 //
|
Chris@16
|
31 // This is an implementation artifact used to pick intelligent default
|
Chris@16
|
32 // values when the user specified boost::use_default as a template
|
Chris@16
|
33 // parameter.
|
Chris@16
|
34 template<
|
Chris@16
|
35 class T,
|
Chris@16
|
36 class Default
|
Chris@16
|
37 >
|
Chris@16
|
38 struct any_range_default_help
|
Chris@16
|
39 : mpl::eval_if<
|
Chris@16
|
40 is_same<T, use_default>
|
Chris@16
|
41 , Default
|
Chris@16
|
42 , mpl::identity<T>
|
Chris@16
|
43 >
|
Chris@16
|
44 {
|
Chris@16
|
45 };
|
Chris@16
|
46
|
Chris@16
|
47 template<
|
Chris@16
|
48 class WrappedRange
|
Chris@16
|
49 , class Value
|
Chris@16
|
50 , class Reference
|
Chris@16
|
51 >
|
Chris@16
|
52 struct any_range_value_type
|
Chris@16
|
53 {
|
Chris@16
|
54 # ifdef BOOST_ITERATOR_REF_CONSTNESS_KILLS_WRITABILITY
|
Chris@16
|
55 typedef typename any_range_default_help<
|
Chris@16
|
56 Value
|
Chris@16
|
57 , mpl::eval_if<
|
Chris@16
|
58 is_same<Reference, use_default>
|
Chris@16
|
59 , range_value<
|
Chris@16
|
60 typename remove_const<WrappedRange>
|
Chris@16
|
61 ::type>
|
Chris@16
|
62 , remove_reference<Reference>
|
Chris@16
|
63 >
|
Chris@16
|
64 >::type type;
|
Chris@16
|
65 # else
|
Chris@16
|
66 typedef typename any_range_default_help<
|
Chris@16
|
67 Value
|
Chris@16
|
68 , range_value<
|
Chris@16
|
69 typename remove_const<WrappedRange>
|
Chris@16
|
70 ::type>
|
Chris@16
|
71 >::type type;
|
Chris@16
|
72 # endif
|
Chris@16
|
73 };
|
Chris@16
|
74
|
Chris@16
|
75 template<
|
Chris@16
|
76 class Value
|
Chris@16
|
77 , class Traversal
|
Chris@16
|
78 , class Reference
|
Chris@16
|
79 , class Difference
|
Chris@16
|
80 , class Buffer = use_default
|
Chris@16
|
81 >
|
Chris@16
|
82 class any_range
|
Chris@16
|
83 : public iterator_range<
|
Chris@16
|
84 any_iterator<
|
Chris@16
|
85 Value
|
Chris@16
|
86 , Traversal
|
Chris@16
|
87 , Reference
|
Chris@16
|
88 , Difference
|
Chris@16
|
89 , typename any_range_default_help<
|
Chris@16
|
90 Buffer
|
Chris@16
|
91 , mpl::identity<any_iterator_default_buffer>
|
Chris@16
|
92 >::type
|
Chris@16
|
93 >
|
Chris@16
|
94 >
|
Chris@16
|
95 {
|
Chris@16
|
96 typedef iterator_range<
|
Chris@16
|
97 any_iterator<
|
Chris@16
|
98 Value
|
Chris@16
|
99 , Traversal
|
Chris@16
|
100 , Reference
|
Chris@16
|
101 , Difference
|
Chris@16
|
102 , typename any_range_default_help<
|
Chris@16
|
103 Buffer
|
Chris@16
|
104 , mpl::identity<any_iterator_default_buffer>
|
Chris@16
|
105 >::type
|
Chris@16
|
106 >
|
Chris@16
|
107 > base_type;
|
Chris@16
|
108
|
Chris@16
|
109 struct enabler {};
|
Chris@16
|
110 struct disabler {};
|
Chris@16
|
111 public:
|
Chris@16
|
112 any_range()
|
Chris@16
|
113 {
|
Chris@16
|
114 }
|
Chris@16
|
115
|
Chris@16
|
116 any_range(const any_range& other)
|
Chris@16
|
117 : base_type(other)
|
Chris@16
|
118 {
|
Chris@16
|
119 }
|
Chris@16
|
120
|
Chris@16
|
121 template<class WrappedRange>
|
Chris@16
|
122 any_range(WrappedRange& wrapped_range)
|
Chris@16
|
123 : base_type(boost::begin(wrapped_range),
|
Chris@16
|
124 boost::end(wrapped_range))
|
Chris@16
|
125 {
|
Chris@16
|
126 }
|
Chris@16
|
127
|
Chris@16
|
128 template<class WrappedRange>
|
Chris@16
|
129 any_range(const WrappedRange& wrapped_range)
|
Chris@16
|
130 : base_type(boost::begin(wrapped_range),
|
Chris@16
|
131 boost::end(wrapped_range))
|
Chris@16
|
132 {
|
Chris@16
|
133 }
|
Chris@16
|
134
|
Chris@16
|
135 template<
|
Chris@16
|
136 class OtherValue
|
Chris@16
|
137 , class OtherTraversal
|
Chris@16
|
138 , class OtherReference
|
Chris@16
|
139 , class OtherDifference
|
Chris@16
|
140 >
|
Chris@16
|
141 any_range(const any_range<
|
Chris@16
|
142 OtherValue
|
Chris@16
|
143 , OtherTraversal
|
Chris@16
|
144 , OtherReference
|
Chris@16
|
145 , OtherDifference
|
Chris@16
|
146 , Buffer
|
Chris@16
|
147 >& other)
|
Chris@16
|
148 : base_type(boost::begin(other), boost::end(other))
|
Chris@16
|
149 {
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 template<class Iterator>
|
Chris@16
|
153 any_range(Iterator first, Iterator last)
|
Chris@16
|
154 : base_type(first, last)
|
Chris@16
|
155 {
|
Chris@16
|
156 }
|
Chris@16
|
157 };
|
Chris@16
|
158
|
Chris@16
|
159 template<
|
Chris@16
|
160 class WrappedRange
|
Chris@16
|
161 , class Value = use_default
|
Chris@16
|
162 , class Traversal = use_default
|
Chris@16
|
163 , class Reference = use_default
|
Chris@16
|
164 , class Difference = use_default
|
Chris@16
|
165 , class Buffer = use_default
|
Chris@16
|
166 >
|
Chris@16
|
167 struct any_range_type_generator
|
Chris@16
|
168 {
|
Chris@16
|
169 BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<WrappedRange> ));
|
Chris@16
|
170 typedef any_range<
|
Chris@16
|
171 typename any_range_value_type<
|
Chris@16
|
172 WrappedRange
|
Chris@16
|
173 , Value
|
Chris@16
|
174 , typename any_range_default_help<
|
Chris@16
|
175 Reference
|
Chris@16
|
176 , range_reference<WrappedRange>
|
Chris@16
|
177 >::type
|
Chris@16
|
178 >::type
|
Chris@16
|
179 , typename any_range_default_help<
|
Chris@16
|
180 Traversal
|
Chris@16
|
181 , iterator_traversal<
|
Chris@16
|
182 typename range_iterator<WrappedRange>::type
|
Chris@16
|
183 >
|
Chris@16
|
184 >::type
|
Chris@16
|
185 , typename any_range_default_help<
|
Chris@16
|
186 Reference
|
Chris@16
|
187 , range_reference<WrappedRange>
|
Chris@16
|
188 >::type
|
Chris@16
|
189 , typename any_range_default_help<
|
Chris@16
|
190 Difference
|
Chris@16
|
191 , range_difference<WrappedRange>
|
Chris@16
|
192 >::type
|
Chris@16
|
193 , typename any_range_default_help<
|
Chris@16
|
194 Buffer
|
Chris@16
|
195 , mpl::identity<any_iterator_default_buffer>
|
Chris@16
|
196 >::type
|
Chris@16
|
197 > type;
|
Chris@16
|
198 };
|
Chris@16
|
199 } // namespace range_detail
|
Chris@16
|
200
|
Chris@16
|
201 using range_detail::any_range;
|
Chris@16
|
202 using range_detail::any_range_type_generator;
|
Chris@16
|
203 } // namespace boost
|
Chris@16
|
204
|
Chris@16
|
205 #endif // include guard
|