Go to the documentation of this file.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
00056
00057
00058
00059
00060 #ifndef _STL_ITERATOR_BASE_FUNCS_H
00061 #define _STL_ITERATOR_BASE_FUNCS_H 1
00062
00063 #pragma GCC system_header
00064
00065 #include <bits/concept_check.h>
00066
00067 _GLIBCXX_BEGIN_NAMESPACE(std)
00068
00069 template<typename _InputIterator>
00070 inline typename iterator_traits<_InputIterator>::difference_type
00071 __distance(_InputIterator __first, _InputIterator __last,
00072 input_iterator_tag)
00073 {
00074
00075 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00076
00077 typename iterator_traits<_InputIterator>::difference_type __n = 0;
00078 while (__first != __last)
00079 {
00080 ++__first;
00081 ++__n;
00082 }
00083 return __n;
00084 }
00085
00086 template<typename _RandomAccessIterator>
00087 inline typename iterator_traits<_RandomAccessIterator>::difference_type
00088 __distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
00089 random_access_iterator_tag)
00090 {
00091
00092 __glibcxx_function_requires(_RandomAccessIteratorConcept<
00093 _RandomAccessIterator>)
00094 return __last - __first;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 template<typename _InputIterator>
00110 inline typename iterator_traits<_InputIterator>::difference_type
00111 distance(_InputIterator __first, _InputIterator __last)
00112 {
00113
00114 return std::__distance(__first, __last,
00115 std::__iterator_category(__first));
00116 }
00117
00118 template<typename _InputIterator, typename _Distance>
00119 inline void
00120 __advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
00121 {
00122
00123 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00124 while (__n--)
00125 ++__i;
00126 }
00127
00128 template<typename _BidirectionalIterator, typename _Distance>
00129 inline void
00130 __advance(_BidirectionalIterator& __i, _Distance __n,
00131 bidirectional_iterator_tag)
00132 {
00133
00134 __glibcxx_function_requires(_BidirectionalIteratorConcept<
00135 _BidirectionalIterator>)
00136 if (__n > 0)
00137 while (__n--)
00138 ++__i;
00139 else
00140 while (__n++)
00141 --__i;
00142 }
00143
00144 template<typename _RandomAccessIterator, typename _Distance>
00145 inline void
00146 __advance(_RandomAccessIterator& __i, _Distance __n,
00147 random_access_iterator_tag)
00148 {
00149
00150 __glibcxx_function_requires(_RandomAccessIteratorConcept<
00151 _RandomAccessIterator>)
00152 __i += __n;
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167 template<typename _InputIterator, typename _Distance>
00168 inline void
00169 advance(_InputIterator& __i, _Distance __n)
00170 {
00171
00172 typename iterator_traits<_InputIterator>::difference_type __d = __n;
00173 std::__advance(__i, __d, std::__iterator_category(__i));
00174 }
00175
00176 _GLIBCXX_END_NAMESPACE
00177
00178 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00179
00180 #include <ext/type_traits.h>
00181
00182 _GLIBCXX_BEGIN_NAMESPACE(std)
00183
00184 template<typename _ForwardIterator>
00185 inline typename
00186 __gnu_cxx::__enable_if<__is_iterator<_ForwardIterator>::__value,
00187 _ForwardIterator>::__type
00188 next(_ForwardIterator __x, typename
00189 iterator_traits<_ForwardIterator>::difference_type __n = 1)
00190 {
00191 std::advance(__x, __n);
00192 return __x;
00193 }
00194
00195 template<typename _BidirectionalIterator>
00196 inline typename
00197 __gnu_cxx::__enable_if<__is_iterator<_BidirectionalIterator>::__value,
00198 _BidirectionalIterator>::__type
00199 prev(_BidirectionalIterator __x, typename
00200 iterator_traits<_BidirectionalIterator>::difference_type __n = 1)
00201 {
00202 std::advance(__x, -__n);
00203 return __x;
00204 }
00205
00206 _GLIBCXX_END_NAMESPACE
00207
00208 #endif // __GXX_EXPERIMENTAL_CXX0X__
00209
00210 #endif