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 namespace std _GLIBCXX_VISIBILITY(default)
00068 {
00069 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00070
00071 template<typename _InputIterator>
00072 inline typename iterator_traits<_InputIterator>::difference_type
00073 __distance(_InputIterator __first, _InputIterator __last,
00074 input_iterator_tag)
00075 {
00076
00077 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00078
00079 typename iterator_traits<_InputIterator>::difference_type __n = 0;
00080 while (__first != __last)
00081 {
00082 ++__first;
00083 ++__n;
00084 }
00085 return __n;
00086 }
00087
00088 template<typename _RandomAccessIterator>
00089 inline typename iterator_traits<_RandomAccessIterator>::difference_type
00090 __distance(_RandomAccessIterator __first, _RandomAccessIterator __last,
00091 random_access_iterator_tag)
00092 {
00093
00094 __glibcxx_function_requires(_RandomAccessIteratorConcept<
00095 _RandomAccessIterator>)
00096 return __last - __first;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 template<typename _InputIterator>
00112 inline typename iterator_traits<_InputIterator>::difference_type
00113 distance(_InputIterator __first, _InputIterator __last)
00114 {
00115
00116 return std::__distance(__first, __last,
00117 std::__iterator_category(__first));
00118 }
00119
00120 template<typename _InputIterator, typename _Distance>
00121 inline void
00122 __advance(_InputIterator& __i, _Distance __n, input_iterator_tag)
00123 {
00124
00125 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00126 while (__n--)
00127 ++__i;
00128 }
00129
00130 template<typename _BidirectionalIterator, typename _Distance>
00131 inline void
00132 __advance(_BidirectionalIterator& __i, _Distance __n,
00133 bidirectional_iterator_tag)
00134 {
00135
00136 __glibcxx_function_requires(_BidirectionalIteratorConcept<
00137 _BidirectionalIterator>)
00138 if (__n > 0)
00139 while (__n--)
00140 ++__i;
00141 else
00142 while (__n++)
00143 --__i;
00144 }
00145
00146 template<typename _RandomAccessIterator, typename _Distance>
00147 inline void
00148 __advance(_RandomAccessIterator& __i, _Distance __n,
00149 random_access_iterator_tag)
00150 {
00151
00152 __glibcxx_function_requires(_RandomAccessIteratorConcept<
00153 _RandomAccessIterator>)
00154 __i += __n;
00155 }
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 template<typename _InputIterator, typename _Distance>
00170 inline void
00171 advance(_InputIterator& __i, _Distance __n)
00172 {
00173
00174 typename iterator_traits<_InputIterator>::difference_type __d = __n;
00175 std::__advance(__i, __d, std::__iterator_category(__i));
00176 }
00177
00178 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00179
00180 template<typename _ForwardIterator>
00181 inline _ForwardIterator
00182 next(_ForwardIterator __x, typename
00183 iterator_traits<_ForwardIterator>::difference_type __n = 1)
00184 {
00185 std::advance(__x, __n);
00186 return __x;
00187 }
00188
00189 template<typename _BidirectionalIterator>
00190 inline _BidirectionalIterator
00191 prev(_BidirectionalIterator __x, typename
00192 iterator_traits<_BidirectionalIterator>::difference_type __n = 1)
00193 {
00194 std::advance(__x, -__n);
00195 return __x;
00196 }
00197
00198 #endif // __GXX_EXPERIMENTAL_CXX0X__
00199
00200 _GLIBCXX_END_NAMESPACE_VERSION
00201 }
00202
00203 #endif