00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00064 #ifndef __GLIBCPP_INTERNAL_ITERATOR_BASE_FUNCS_H
00065 #define __GLIBCPP_INTERNAL_ITERATOR_BASE_FUNCS_H
00066
00067 #pragma GCC system_header
00068 #include <bits/concept_check.h>
00069
00070 namespace std
00071 {
00072 template<typename _InputIterator>
00073 inline typename iterator_traits<_InputIterator>::difference_type
00074 __distance(_InputIterator __first, _InputIterator __last,
00075 input_iterator_tag)
00076 {
00077
00078 __glibcpp_function_requires(_InputIteratorConcept<_InputIterator>)
00079
00080 typename iterator_traits<_InputIterator>::difference_type __n = 0;
00081 while (__first != __last) {
00082 ++__first; ++__n;
00083 }
00084 return __n;
00085 }
00086
00087 template<typename _RandomAccessIterator>
00088 inline typename iterator_traits<_RandomAccessIterator>::difference_type
00089 __distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
00090 random_access_iterator_tag)
00091 {
00092
00093 __glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>)
00094 return __last - __first;
00095 }
00096
00109 template<typename _InputIterator>
00110 inline typename iterator_traits<_InputIterator>::difference_type
00111 distance(_InputIterator __first, _InputIterator __last)
00112 {
00113
00114 return __distance(__first, __last, __iterator_category(__first));
00115 }
00116
00117 template<typename _InputIter, typename _Distance>
00118 inline void
00119 __advance(_InputIter& __i, _Distance __n, input_iterator_tag)
00120 {
00121
00122 __glibcpp_function_requires(_InputIteratorConcept<_InputIter>)
00123 while (__n--) ++__i;
00124 }
00125
00126 template<typename _BidirectionalIterator, typename _Distance>
00127 inline void
00128 __advance(_BidirectionalIterator& __i, _Distance __n,
00129 bidirectional_iterator_tag)
00130 {
00131
00132 __glibcpp_function_requires(_BidirectionalIteratorConcept<_BidirectionalIterator>)
00133
00134 if (__n > 0)
00135 while (__n--) ++__i;
00136 else
00137 while (__n++) --__i;
00138 }
00139
00140 template<typename _RandomAccessIterator, typename _Distance>
00141 inline void
00142 __advance(_RandomAccessIterator& __i, _Distance __n,
00143 random_access_iterator_tag)
00144 {
00145
00146 __glibcpp_function_requires(_RandomAccessIteratorConcept<_RandomAccessIterator>)
00147 __i += __n;
00148 }
00149
00162 template<typename _InputIterator, typename _Distance>
00163 inline void
00164 advance(_InputIterator& __i, _Distance __n)
00165 {
00166
00167 __advance(__i, __n, __iterator_category(__i));
00168 }
00169 }
00170
00171 #endif