56 #ifndef _STL_NUMERIC_H 57 #define _STL_NUMERIC_H 1 64 namespace std _GLIBCXX_VISIBILITY(default)
66 _GLIBCXX_BEGIN_NAMESPACE_VERSION
72 #if __cplusplus >= 201103L 85 template<
typename _ForwardIterator,
typename _Tp>
87 iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
90 __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
92 __glibcxx_function_requires(_ConvertibleConcept<_Tp,
93 typename iterator_traits<_ForwardIterator>::value_type>)
94 __glibcxx_requires_valid_range(__first, __last);
96 for (; __first != __last; ++__first)
104 _GLIBCXX_END_NAMESPACE_VERSION
106 _GLIBCXX_BEGIN_NAMESPACE_ALGO
108 #if __cplusplus > 201703L 111 # define _GLIBCXX_MOVE_IF_20(_E) std::move(_E) 113 # define _GLIBCXX_MOVE_IF_20(_E) _E 130 template<
typename _InputIterator,
typename _Tp>
132 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
135 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
136 __glibcxx_requires_valid_range(__first, __last);
138 for (; __first != __last; ++__first)
139 __init = _GLIBCXX_MOVE_IF_20(__init) + *__first;
156 template<
typename _InputIterator,
typename _Tp,
typename _BinaryOperation>
158 accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
159 _BinaryOperation __binary_op)
162 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
163 __glibcxx_requires_valid_range(__first, __last);
165 for (; __first != __last; ++__first)
166 __init = __binary_op(_GLIBCXX_MOVE_IF_20(__init), *__first);
184 template<
typename _InputIterator1,
typename _InputIterator2,
typename _Tp>
187 _InputIterator2 __first2, _Tp __init)
190 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
191 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
192 __glibcxx_requires_valid_range(__first1, __last1);
194 for (; __first1 != __last1; ++__first1, (void)++__first2)
195 __init = _GLIBCXX_MOVE_IF_20(__init) + (*__first1 * *__first2);
215 template<
typename _InputIterator1,
typename _InputIterator2,
typename _Tp,
216 typename _BinaryOperation1,
typename _BinaryOperation2>
219 _InputIterator2 __first2, _Tp __init,
220 _BinaryOperation1 __binary_op1,
221 _BinaryOperation2 __binary_op2)
224 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
225 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
226 __glibcxx_requires_valid_range(__first1, __last1);
228 for (; __first1 != __last1; ++__first1, (void)++__first2)
229 __init = __binary_op1(_GLIBCXX_MOVE_IF_20(__init),
230 __binary_op2(*__first1, *__first2));
248 template<
typename _InputIterator,
typename _OutputIterator>
251 _OutputIterator __result)
253 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
256 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
257 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
259 __glibcxx_requires_valid_range(__first, __last);
261 if (__first == __last)
263 _ValueType __value = *__first;
265 while (++__first != __last)
267 __value = _GLIBCXX_MOVE_IF_20(__value) + *__first;
268 *++__result = __value;
288 template<
typename _InputIterator,
typename _OutputIterator,
289 typename _BinaryOperation>
292 _OutputIterator __result, _BinaryOperation __binary_op)
294 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
297 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
298 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
300 __glibcxx_requires_valid_range(__first, __last);
302 if (__first == __last)
304 _ValueType __value = *__first;
306 while (++__first != __last)
308 __value = __binary_op(_GLIBCXX_MOVE_IF_20(__value), *__first);
309 *++__result = __value;
328 template<
typename _InputIterator,
typename _OutputIterator>
331 _InputIterator __last, _OutputIterator __result)
333 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
336 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
337 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
339 __glibcxx_requires_valid_range(__first, __last);
341 if (__first == __last)
343 _ValueType __value = *__first;
345 while (++__first != __last)
347 _ValueType __tmp = *__first;
348 *++__result = __tmp - _GLIBCXX_MOVE_IF_20(__value);
349 __value = _GLIBCXX_MOVE(__tmp);
370 template<
typename _InputIterator,
typename _OutputIterator,
371 typename _BinaryOperation>
374 _OutputIterator __result, _BinaryOperation __binary_op)
376 typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
379 __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
380 __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
382 __glibcxx_requires_valid_range(__first, __last);
384 if (__first == __last)
386 _ValueType __value = *__first;
388 while (++__first != __last)
390 _ValueType __tmp = *__first;
391 *++__result = __binary_op(__tmp, _GLIBCXX_MOVE_IF_20(__value));
392 __value = _GLIBCXX_MOVE(__tmp);
399 #undef _GLIBCXX_MOVE_IF_20 401 _GLIBCXX_END_NAMESPACE_ALGO
ISO C++ entities toplevel namespace is std.
_Tp inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
Compute inner product of two ranges.
void iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
Create a range of sequentially increasing values.
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Accumulate values in a range.
_OutputIterator adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return differences between adjacent values.
_OutputIterator partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
Return list of partial sums.