1#ifndef _STDEX_ITERATOR_H
2#define _STDEX_ITERATOR_H
16#ifdef _STDEX_NATIVE_CPP11_SUPPORT
18#define _STDEX_DELETED_FUNCTION =delete
19#define _STDEX_NOEXCEPT_FUNCTION noexcept
23#define _STDEX_DELETED_FUNCTION
24#define _STDEX_NOEXCEPT_FUNCTION throw()
30 namespace iterator_cpp11
32#ifndef STDEX_DO_NOT_ADD_CPP11_STD
39 typedef std::size_t size_t;
44 using std::iterator_traits;
46 using std::input_iterator_tag;
47 using std::output_iterator_tag;
48 using std::forward_iterator_tag;
49 using std::bidirectional_iterator_tag;
50 using std::random_access_iterator_tag;
57 using std::reverse_iterator;
68 using std::back_insert_iterator;
70 using std::back_inserter;
72 using std::front_insert_iterator;
74 using std::front_inserter;
76 using std::insert_iterator;
83 using std::istream_iterator;
85 using std::ostream_iterator;
87 using std::istreambuf_iterator;
89 using std::ostreambuf_iterator;
101 struct _iterator_false_type {
static const bool value =
false; };
102 struct _iterator_true_type {
static const bool value =
true; };
104 template <
bool,
class _Tp>
105 struct _iterator_enable_if
108 struct _iterator_enable_if_dummy;
110 typedef _iterator_enable_if_dummy(&type)[1];
114 struct _iterator_enable_if<true, _Tp>
119 template<
class,
class>
120 struct _iterator_is_same:
125 struct _iterator_is_same<_Tp, _Tp>:
130 struct _iterator_is_reference:
135 struct _iterator_is_reference<_Tp&> :
140 struct _iterator_is_not_void :
145 struct _iterator_is_not_void<void> :
149 template<
bool,
class _ItType>
150 struct _iterator_traits_enable_if
152 typedef _iterator_enable_if<false, void>::type type;
153 typedef _iterator_enable_if<false, void>::type iterator_category;
154 typedef _iterator_enable_if<false, void>::type value_type;
155 typedef _iterator_enable_if<false, void>::type difference_type;
156 typedef _iterator_enable_if<false, void>::type pointer;
157 typedef _iterator_enable_if<false, void>::type reference;
160 template<
class _ItType>
161 struct _iterator_traits_enable_if<true, _ItType>:
162 std::iterator_traits<_ItType>,
163 _iterator_enable_if<true, _ItType>
166 typedef char _iterator_yes_type;
167 struct _iterator_no_type
172 _iterator_yes_type _input_iterator_cat_tester(std::input_iterator_tag*);
173 _iterator_no_type _input_iterator_cat_tester(...);
174 _iterator_yes_type _output_iterator_cat_tester(std::output_iterator_tag*);
175 _iterator_no_type _output_iterator_cat_tester(...);
176 _iterator_yes_type _forward_iterator_cat_tester(std::forward_iterator_tag*);
177 _iterator_no_type _forward_iterator_cat_tester(...);
178 _iterator_yes_type _bidirectional_iterator_cat_tester(std::bidirectional_iterator_tag*);
179 _iterator_no_type _bidirectional_iterator_cat_tester(...);
180 _iterator_yes_type _random_access_iterator_cat_tester(std::random_access_iterator_tag*);
181 _iterator_no_type _random_access_iterator_cat_tester(...);
183 template<
class _ItCategory,
class>
184 struct _iterator_cat_is;
186 template<
class _ItCategory>
187 struct _iterator_cat_is<_ItCategory, std::input_iterator_tag>
189 static const bool value =
sizeof(_input_iterator_cat_tester((_ItCategory*)(0))) ==
sizeof(_iterator_yes_type);
192 template<
class _ItCategory>
193 struct _iterator_cat_is<_ItCategory, std::output_iterator_tag>
195 static const bool value =
sizeof(_output_iterator_cat_tester((_ItCategory*)(0))) ==
sizeof(_iterator_yes_type);
198 template<
class _ItCategory>
199 struct _iterator_cat_is<_ItCategory, std::forward_iterator_tag>
201 static const bool value =
sizeof(_forward_iterator_cat_tester((_ItCategory*)(0))) ==
sizeof(_iterator_yes_type);
204 template<
class _ItCategory>
205 struct _iterator_cat_is<_ItCategory, std::bidirectional_iterator_tag>
207 static const bool value =
sizeof(_bidirectional_iterator_cat_tester((_ItCategory*)(0))) ==
sizeof(_iterator_yes_type);
210 template<
class _ItCategory>
211 struct _iterator_cat_is<_ItCategory, std::random_access_iterator_tag>
213 static const bool value =
sizeof(_random_access_iterator_cat_tester((_ItCategory*)(0))) ==
sizeof(_iterator_yes_type);
216 template<
class _ItCategory,
class _CheckCategory>
217 struct _iterator_cat_is_valid:
218 _iterator_cat_is<_ItCategory, _CheckCategory>
221 template<
class _ItCategory>
222 struct _iterator_cat_is_valid<_ItCategory, std::output_iterator_tag>
224 static const bool value =
225 _iterator_cat_is<_ItCategory, std::forward_iterator_tag>::value ||
226 _iterator_cat_is<_ItCategory, std::output_iterator_tag>::value;
229 template<
class _InputIt>
230 struct _if_iterator_cat_is_input:
231 _iterator_traits_enable_if<
233 typename std::iterator_traits<_InputIt>::iterator_category,
234 std::input_iterator_tag
235 >::value == bool(true),
240 template<
class _OutputIt>
241 struct _if_iterator_is_valid_output:
242 _iterator_traits_enable_if<
243 _iterator_cat_is_valid<
244 typename std::iterator_traits<_OutputIt>::iterator_category,
245 std::output_iterator_tag
246 >::value == bool(true),
251 template<
class _ForwardIt>
252 struct _if_iterator_cat_is_forward:
253 _iterator_traits_enable_if<
255 typename std::iterator_traits<_ForwardIt>::iterator_category,
256 std::forward_iterator_tag
257 >::value == bool(true),
262 template<
class _B
idirIt>
263 struct _if_iterator_cat_is_bi:
264 _iterator_traits_enable_if<
266 typename std::iterator_traits<_BidirIt>::iterator_category,
267 std::bidirectional_iterator_tag
268 >::value == bool(true),
273 template<
class _RandomIt>
274 struct _if_iterator_cat_is_rand_access:
275 _if_iterator_cat_is_bi<_RandomIt>
284 struct _is_legacy_iterator:
285 _iterator_is_not_void<
286 typename std::iterator_traits<_It>::reference>
289 template<
class _It,
bool>
290 struct _is_legacy_input_iterator_impl :
291 _iterator_false_type { };
294 struct _is_legacy_input_iterator_impl<_It, true> :
295 _iterator_cat_is_valid<_It, std::input_iterator_tag>
299 struct _is_legacy_input_iterator:
300 _is_legacy_input_iterator_impl<_It, _is_legacy_iterator<_It>::value>
303 template<
class _It,
bool>
304 struct _is_legacy_forward_iterator_impl :
305 _iterator_false_type { };
308 struct _is_legacy_forward_iterator_impl<_It, true> :
309 _iterator_cat_is_valid<_It, std::forward_iterator_tag>
313 struct _is_legacy_forward_iterator :
314 _is_legacy_forward_iterator_impl<_It, _is_legacy_input_iterator<_It>::value>
317 template<
class _It,
bool>
318 struct _is_legacy_bi_iterator_impl :
319 _iterator_false_type { };
322 struct _is_legacy_bi_iterator_impl<_It, true> :
323 _iterator_cat_is_valid<_It, std::bidirectional_iterator_tag>
327 struct _is_legacy_bi_iterator :
328 _is_legacy_bi_iterator_impl<_It, _is_legacy_forward_iterator<_It>::value>
331 template<
class _It,
bool>
332 struct _is_legacy_rand_iterator_impl :
333 _iterator_false_type { };
336 struct _is_legacy_rand_iterator_impl<_It, true> :
337 _iterator_cat_is_valid<_It, std::random_access_iterator_tag>
341 struct _is_legacy_rand_iterator :
342 _is_legacy_rand_iterator_impl<_It, _is_legacy_bi_iterator<_It>::value>
346 namespace iterator_cpp11
350 template<
class _ForwardIt>
352 _ForwardIt next(_ForwardIt _it,
353 typename detail::_if_iterator_cat_is_forward<_ForwardIt>::difference_type _n)
355 std::advance(_it, _n);
361 template<
class _ForwardIt>
363 _ForwardIt next(_ForwardIt _it)
365 return iterator_cpp11::next(_it, 1);
370 template<
class _B
idirIt>
372 _BidirIt prev(_BidirIt _it,
373 typename detail::_if_iterator_cat_is_bi<_BidirIt>::difference_type _n)
375 std::advance(_it, -_n);
381 template<
class _B
idirIt>
383 _BidirIt prev(_BidirIt _it)
385 return iterator_cpp11::prev(_it, 1);
391 using iterator_cpp11::next;
395 using iterator_cpp11::prev;
399 namespace iterator_cpp11
403 template<
class _ContainerType>
405 typename _ContainerType::iterator begin(_ContainerType &value)
407 return (value.begin());
412 template<
class _ContainerType>
414 typename _ContainerType::const_iterator begin(
const _ContainerType &value)
416 return (value.begin());
421 template<
class _Tp, cstddef::
size_t Size>
423 _Tp* begin(_Tp(&value)[Size]) _STDEX_NOEXCEPT_FUNCTION
430 template<
class _Tp, cstddef::
size_t Size>
432 const _Tp* begin(
const _Tp(&value)[Size]) _STDEX_NOEXCEPT_FUNCTION
439 template<
class _ContainerType>
441 typename _ContainerType::iterator end(_ContainerType &value)
443 return (value.end());
448 template<
class _ContainerType>
450 typename _ContainerType::const_iterator end(
const _ContainerType &value)
452 return (value.end());
457 template<
class _Tp, cstddef::
size_t Size>
459 _Tp* end(_Tp(&value)[Size]) _STDEX_NOEXCEPT_FUNCTION
461 return (value + Size);
466 template<
class _Tp, cstddef::
size_t Size>
468 const _Tp* end(
const _Tp(&value)[Size]) _STDEX_NOEXCEPT_FUNCTION
470 return (value + Size);
476 using iterator_cpp11::begin;
482 using iterator_cpp11::end;
487#undef _STDEX_DELETED_FUNCTION
488#undef _STDEX_NOEXCEPT_FUNCTION