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
00061 #ifndef _STL_NUMERIC_H
00062 #define _STL_NUMERIC_H 1
00063
00064 #include <debug/debug.h>
00065
00066 _GLIBCXX_BEGIN_NAMESPACE(std)
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 template<typename _InputIterator, typename _Tp>
00080 _Tp
00081 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
00082 {
00083
00084 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00085 __glibcxx_requires_valid_range(__first, __last);
00086
00087 for (; __first != __last; ++__first)
00088 __init = __init + *__first;
00089 return __init;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
00106 _Tp
00107 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
00108 _BinaryOperation __binary_op)
00109 {
00110
00111 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00112 __glibcxx_requires_valid_range(__first, __last);
00113
00114 for (; __first != __last; ++__first)
00115 __init = __binary_op(__init, *__first);
00116 return __init;
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 template<typename _InputIterator1, typename _InputIterator2, typename _Tp>
00134 _Tp
00135 inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
00136 _InputIterator2 __first2, _Tp __init)
00137 {
00138
00139 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
00140 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
00141 __glibcxx_requires_valid_range(__first1, __last1);
00142
00143 for (; __first1 != __last1; ++__first1, ++__first2)
00144 __init = __init + (*__first1 * *__first2);
00145 return __init;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
00165 typename _BinaryOperation1, typename _BinaryOperation2>
00166 _Tp
00167 inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
00168 _InputIterator2 __first2, _Tp __init,
00169 _BinaryOperation1 __binary_op1,
00170 _BinaryOperation2 __binary_op2)
00171 {
00172
00173 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
00174 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
00175 __glibcxx_requires_valid_range(__first1, __last1);
00176
00177 for (; __first1 != __last1; ++__first1, ++__first2)
00178 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
00179 return __init;
00180 }
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 template<typename _InputIterator, typename _OutputIterator>
00197 _OutputIterator
00198 partial_sum(_InputIterator __first, _InputIterator __last,
00199 _OutputIterator __result)
00200 {
00201 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
00202
00203
00204 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00205 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
00206 _ValueType>)
00207 __glibcxx_requires_valid_range(__first, __last);
00208
00209 if (__first == __last)
00210 return __result;
00211 _ValueType __value = *__first;
00212 *__result = __value;
00213 while (++__first != __last)
00214 {
00215 __value = __value + *__first;
00216 *++__result = __value;
00217 }
00218 return ++__result;
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 template<typename _InputIterator, typename _OutputIterator,
00236 typename _BinaryOperation>
00237 _OutputIterator
00238 partial_sum(_InputIterator __first, _InputIterator __last,
00239 _OutputIterator __result, _BinaryOperation __binary_op)
00240 {
00241 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
00242
00243
00244 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00245 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
00246 _ValueType>)
00247 __glibcxx_requires_valid_range(__first, __last);
00248
00249 if (__first == __last)
00250 return __result;
00251 _ValueType __value = *__first;
00252 *__result = __value;
00253 while (++__first != __last)
00254 {
00255 __value = __binary_op(__value, *__first);
00256 *++__result = __value;
00257 }
00258 return ++__result;
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 template<typename _InputIterator, typename _OutputIterator>
00273 _OutputIterator
00274 adjacent_difference(_InputIterator __first,
00275 _InputIterator __last, _OutputIterator __result)
00276 {
00277 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
00278
00279
00280 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00281 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
00282 _ValueType>)
00283 __glibcxx_requires_valid_range(__first, __last);
00284
00285 if (__first == __last)
00286 return __result;
00287 _ValueType __value = *__first;
00288 *__result = __value;
00289 while (++__first != __last)
00290 {
00291 _ValueType __tmp = *__first;
00292 *++__result = __tmp - __value;
00293 __value = __tmp;
00294 }
00295 return ++__result;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 template<typename _InputIterator, typename _OutputIterator,
00311 typename _BinaryOperation>
00312 _OutputIterator
00313 adjacent_difference(_InputIterator __first, _InputIterator __last,
00314 _OutputIterator __result, _BinaryOperation __binary_op)
00315 {
00316 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
00317
00318
00319 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
00320 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
00321 _ValueType>)
00322 __glibcxx_requires_valid_range(__first, __last);
00323
00324 if (__first == __last)
00325 return __result;
00326 _ValueType __value = *__first;
00327 *__result = __value;
00328 while (++__first != __last)
00329 {
00330 _ValueType __tmp = *__first;
00331 *++__result = __binary_op(__tmp, __value);
00332 __value = __tmp;
00333 }
00334 return ++__result;
00335 }
00336
00337 _GLIBCXX_END_NAMESPACE
00338
00339 #endif