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