57 #ifndef _STL_NUMERIC_H
58 #define _STL_NUMERIC_H 1
63 #ifdef __GXX_EXPERIMENTAL_CXX0X__
65 _GLIBCXX_BEGIN_NAMESPACE(std)
78 template<typename _ForwardIterator, typename _Tp>
80 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
83 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
85 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
86 typename iterator_traits<_ForwardIterator>::value_type>)
87 __glibcxx_requires_valid_range(__first, __last);
89 for (; __first != __last; ++__first)
96 _GLIBCXX_END_NAMESPACE
100 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
113 template<typename _InputIterator, typename _Tp>
115 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
118 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
119 __glibcxx_requires_valid_range(__first, __last);
121 for (; __first != __last; ++__first)
122 __init = __init + *__first;
139 template<
typename _InputIterator,
typename _Tp,
typename _BinaryOperation>
141 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
142 _BinaryOperation __binary_op)
145 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
146 __glibcxx_requires_valid_range(__first, __last);
148 for (; __first != __last; ++__first)
149 __init = __binary_op(__init, *__first);
167 template<
typename _InputIterator1,
typename _InputIterator2,
typename _Tp>
169 inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
170 _InputIterator2 __first2, _Tp __init)
173 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
174 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
175 __glibcxx_requires_valid_range(__first1, __last1);
177 for (; __first1 != __last1; ++__first1, ++__first2)
178 __init = __init + (*__first1 * *__first2);
198 template<
typename _InputIterator1,
typename _InputIterator2,
typename _Tp,
199 typename _BinaryOperation1,
typename _BinaryOperation2>
201 inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
202 _InputIterator2 __first2, _Tp __init,
203 _BinaryOperation1 __binary_op1,
204 _BinaryOperation2 __binary_op2)
207 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
208 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
209 __glibcxx_requires_valid_range(__first1, __last1);
211 for (; __first1 != __last1; ++__first1, ++__first2)
212 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
230 template<
typename _InputIterator,
typename _OutputIterator>
232 partial_sum(_InputIterator __first, _InputIterator __last,
233 _OutputIterator __result)
235 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
238 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
239 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
241 __glibcxx_requires_valid_range(__first, __last);
243 if (__first == __last)
245 _ValueType __value = *__first;
247 while (++__first != __last)
249 __value = __value + *__first;
250 *++__result = __value;
269 template<
typename _InputIterator,
typename _OutputIterator,
270 typename _BinaryOperation>
272 partial_sum(_InputIterator __first, _InputIterator __last,
273 _OutputIterator __result, _BinaryOperation __binary_op)
275 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
278 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
279 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
281 __glibcxx_requires_valid_range(__first, __last);
283 if (__first == __last)
285 _ValueType __value = *__first;
287 while (++__first != __last)
289 __value = __binary_op(__value, *__first);
290 *++__result = __value;
306 template<
typename _InputIterator,
typename _OutputIterator>
308 adjacent_difference(_InputIterator __first,
309 _InputIterator __last, _OutputIterator __result)
311 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
314 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
315 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
317 __glibcxx_requires_valid_range(__first, __last);
319 if (__first == __last)
321 _ValueType __value = *__first;
323 while (++__first != __last)
325 _ValueType __tmp = *__first;
326 *++__result = __tmp - __value;
344 template<
typename _InputIterator,
typename _OutputIterator,
345 typename _BinaryOperation>
347 adjacent_difference(_InputIterator __first, _InputIterator __last,
348 _OutputIterator __result, _BinaryOperation __binary_op)
350 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
353 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
354 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
356 __glibcxx_requires_valid_range(__first, __last);
358 if (__first == __last)
360 _ValueType __value = *__first;
362 while (++__first != __last)
364 _ValueType __tmp = *__first;
365 *++__result = __binary_op(__tmp, __value);
371 _GLIBCXX_END_NESTED_NAMESPACE