56 #ifndef _STL_NUMERIC_H
57 #define _STL_NUMERIC_H 1
63 #if __cplusplus >= 201103L
65 namespace std _GLIBCXX_VISIBILITY(default)
67 _GLIBCXX_BEGIN_NAMESPACE_VERSION
80 template<
typename _ForwardIterator,
typename _Tp>
82 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
85 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
87 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
88 typename iterator_traits<_ForwardIterator>::value_type>)
89 __glibcxx_requires_valid_range(__first, __last);
91 for (; __first != __last; ++__first)
98 _GLIBCXX_END_NAMESPACE_VERSION
103 namespace std _GLIBCXX_VISIBILITY(default)
105 _GLIBCXX_BEGIN_NAMESPACE_ALGO
118 template<
typename _InputIterator,
typename _Tp>
120 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
123 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
124 __glibcxx_requires_valid_range(__first, __last);
126 for (; __first != __last; ++__first)
127 __init = __init + *__first;
144 template<
typename _InputIterator,
typename _Tp,
typename _BinaryOperation>
146 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
147 _BinaryOperation __binary_op)
150 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
151 __glibcxx_requires_valid_range(__first, __last);
153 for (; __first != __last; ++__first)
154 __init = __binary_op(__init, *__first);
172 template<
typename _InputIterator1,
typename _InputIterator2,
typename _Tp>
175 _InputIterator2 __first2, _Tp __init)
178 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
179 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
180 __glibcxx_requires_valid_range(__first1, __last1);
182 for (; __first1 != __last1; ++__first1, ++__first2)
183 __init = __init + (*__first1 * *__first2);
203 template<
typename _InputIterator1,
typename _InputIterator2,
typename _Tp,
204 typename _BinaryOperation1,
typename _BinaryOperation2>
207 _InputIterator2 __first2, _Tp __init,
208 _BinaryOperation1 __binary_op1,
209 _BinaryOperation2 __binary_op2)
212 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
213 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
214 __glibcxx_requires_valid_range(__first1, __last1);
216 for (; __first1 != __last1; ++__first1, ++__first2)
217 __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
235 template<
typename _InputIterator,
typename _OutputIterator>
238 _OutputIterator __result)
240 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
243 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
244 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
246 __glibcxx_requires_valid_range(__first, __last);
248 if (__first == __last)
250 _ValueType __value = *__first;
252 while (++__first != __last)
254 __value = __value + *__first;
255 *++__result = __value;
275 template<
typename _InputIterator,
typename _OutputIterator,
276 typename _BinaryOperation>
279 _OutputIterator __result, _BinaryOperation __binary_op)
281 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
284 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
285 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
287 __glibcxx_requires_valid_range(__first, __last);
289 if (__first == __last)
291 _ValueType __value = *__first;
293 while (++__first != __last)
295 __value = __binary_op(__value, *__first);
296 *++__result = __value;
315 template<
typename _InputIterator,
typename _OutputIterator>
318 _InputIterator __last, _OutputIterator __result)
320 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
323 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
324 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
326 __glibcxx_requires_valid_range(__first, __last);
328 if (__first == __last)
330 _ValueType __value = *__first;
332 while (++__first != __last)
334 _ValueType __tmp = *__first;
335 *++__result = __tmp - __value;
336 __value = _GLIBCXX_MOVE(__tmp);
357 template<
typename _InputIterator,
typename _OutputIterator,
358 typename _BinaryOperation>
361 _OutputIterator __result, _BinaryOperation __binary_op)
363 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
366 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
367 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
369 __glibcxx_requires_valid_range(__first, __last);
371 if (__first == __last)
373 _ValueType __value = *__first;
375 while (++__first != __last)
377 _ValueType __tmp = *__first;
378 *++__result = __binary_op(__tmp, __value);
379 __value = _GLIBCXX_MOVE(__tmp);
384 _GLIBCXX_END_NAMESPACE_ALGO
void iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
Create a range of sequentially increasing values.
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
Compute inner product of two ranges.
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
ISO C++ entities toplevel namespace is std.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.
_OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return differences between adjacent values.