STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
stl_numeric.h File Reference
#include <bits/concept_check.h>
#include <debug/debug.h>
#include <bits/move.h>

Go to the source code of this file.

Functions

namespace std _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This is an internal header file, included by other library headers. Do not attempt to use it directly. {numeric}

Function Documentation

namespace std _GLIBCXX_VISIBILITY ( default  )

Accumulate values in a range.

Accumulates the values in the range [first,last) using operator+(). The initial value is init. The values are processed in order.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
Returns
The final sum.

Accumulate values in a range with operation.

Accumulates the values in the range [first,last) using the function object __binary_op. The initial value is __init. The values are processed in order.

Parameters
__firstStart of range.
__lastEnd of range.
__initStarting value to add other values to.
__binary_opFunction object to accumulate with.
Returns
The final sum.

Compute inner product of two ranges.

Starting with an initial value of __init, multiplies successive elements from the two ranges and adds each product into the accumulated value using operator+(). The values in the ranges are processed in order.

Parameters
__first1Start of range 1.
__last1End of range 1.
__first2Start of range 2.
__initStarting value to add other values to.
Returns
The final inner product.

Compute inner product of two ranges.

Starting with an initial value of __init, applies __binary_op2 to successive elements from the two ranges and accumulates each result into the accumulated value using __binary_op1. The values in the ranges are processed in order.

Parameters
__first1Start of range 1.
__last1End of range 1.
__first2Start of range 2.
__initStarting value to add other values to.
__binary_op1Function object to accumulate with.
__binary_op2Function object to apply to pairs of input values.
Returns
The final inner product.

Return list of partial sums

Accumulates the values in the range [first,last) using the + operator. As each successive input value is added into the total, that partial sum is written to __result. Therefore, the first value in __result is the first value of the input, the second value in __result is the sum of the first and second input values, and so on.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sum.
Returns
Iterator pointing just beyond the values written to __result.

Return list of partial sums

Accumulates the values in the range [first,last) using __binary_op. As each successive input value is added into the total, that partial sum is written to __result. Therefore, the first value in __result is the first value of the input, the second value in __result is the sum of the first and second input values, and so on.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sum.
__binary_opFunction object.
Returns
Iterator pointing just beyond the values written to __result.

Return differences between adjacent values.

Computes the difference between adjacent values in the range [first,last) using operator-() and writes the result to __result.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sums.
Returns
Iterator pointing just beyond the values written to result.

_GLIBCXX_RESOLVE_LIB_DEFECTS DR 539. partial_sum and adjacent_difference should mention requirements

Return differences between adjacent values.

Computes the difference between adjacent values in the range [__first,__last) using the function object __binary_op and writes the result to __result.

Parameters
__firstStart of input range.
__lastEnd of input range.
__resultOutput sum.
__binary_opFunction object.
Returns
Iterator pointing just beyond the values written to result.

_GLIBCXX_RESOLVE_LIB_DEFECTS DR 539. partial_sum and adjacent_difference should mention requirements

104 {
105 _GLIBCXX_BEGIN_NAMESPACE_ALGO
106 
118  template<typename _InputIterator, typename _Tp>
119  inline _Tp
120  accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
121  {
122  // concept requirements
123  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
124  __glibcxx_requires_valid_range(__first, __last);
125 
126  for (; __first != __last; ++__first)
127  __init = __init + *__first;
128  return __init;
129  }
130 
144  template<typename _InputIterator, typename _Tp, typename _BinaryOperation>
145  inline _Tp
146  accumulate(_InputIterator __first, _InputIterator __last, _Tp __init,
147  _BinaryOperation __binary_op)
148  {
149  // concept requirements
150  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
151  __glibcxx_requires_valid_range(__first, __last);
152 
153  for (; __first != __last; ++__first)
154  __init = __binary_op(__init, *__first);
155  return __init;
156  }
157 
172  template<typename _InputIterator1, typename _InputIterator2, typename _Tp>
173  inline _Tp
174  inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
175  _InputIterator2 __first2, _Tp __init)
176  {
177  // concept requirements
178  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
179  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
180  __glibcxx_requires_valid_range(__first1, __last1);
181 
182  for (; __first1 != __last1; ++__first1, ++__first2)
183  __init = __init + (*__first1 * *__first2);
184  return __init;
185  }
186 
203  template<typename _InputIterator1, typename _InputIterator2, typename _Tp,
204  typename _BinaryOperation1, typename _BinaryOperation2>
205  inline _Tp
206  inner_product(_InputIterator1 __first1, _InputIterator1 __last1,
207  _InputIterator2 __first2, _Tp __init,
208  _BinaryOperation1 __binary_op1,
209  _BinaryOperation2 __binary_op2)
210  {
211  // concept requirements
212  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator1>)
213  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator2>)
214  __glibcxx_requires_valid_range(__first1, __last1);
215 
216  for (; __first1 != __last1; ++__first1, ++__first2)
217  __init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
218  return __init;
219  }
220 
235  template<typename _InputIterator, typename _OutputIterator>
236  _OutputIterator
237  partial_sum(_InputIterator __first, _InputIterator __last,
238  _OutputIterator __result)
239  {
240  typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
241 
242  // concept requirements
243  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
244  __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
245  _ValueType>)
246  __glibcxx_requires_valid_range(__first, __last);
247 
248  if (__first == __last)
249  return __result;
250  _ValueType __value = *__first;
251  *__result = __value;
252  while (++__first != __last)
253  {
254  __value = __value + *__first;
255  *++__result = __value;
256  }
257  return ++__result;
258  }
259 
275  template<typename _InputIterator, typename _OutputIterator,
276  typename _BinaryOperation>
277  _OutputIterator
278  partial_sum(_InputIterator __first, _InputIterator __last,
279  _OutputIterator __result, _BinaryOperation __binary_op)
280  {
281  typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
282 
283  // concept requirements
284  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
285  __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
286  _ValueType>)
287  __glibcxx_requires_valid_range(__first, __last);
288 
289  if (__first == __last)
290  return __result;
291  _ValueType __value = *__first;
292  *__result = __value;
293  while (++__first != __last)
294  {
295  __value = __binary_op(__value, *__first);
296  *++__result = __value;
297  }
298  return ++__result;
299  }
300 
315  template<typename _InputIterator, typename _OutputIterator>
316  _OutputIterator
317  adjacent_difference(_InputIterator __first,
318  _InputIterator __last, _OutputIterator __result)
319  {
320  typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
321 
322  // concept requirements
323  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
324  __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
325  _ValueType>)
326  __glibcxx_requires_valid_range(__first, __last);
327 
328  if (__first == __last)
329  return __result;
330  _ValueType __value = *__first;
331  *__result = __value;
332  while (++__first != __last)
333  {
334  _ValueType __tmp = *__first;
335  *++__result = __tmp - __value;
336  __value = _GLIBCXX_MOVE(__tmp);
337  }
338  return ++__result;
339  }
340 
357  template<typename _InputIterator, typename _OutputIterator,
358  typename _BinaryOperation>
359  _OutputIterator
360  adjacent_difference(_InputIterator __first, _InputIterator __last,
361  _OutputIterator __result, _BinaryOperation __binary_op)
362  {
363  typedef typename iterator_traits<_InputIterator>::value_type _ValueType;
364 
365  // concept requirements
366  __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>)
367  __glibcxx_function_requires(_OutputIteratorConcept<_OutputIterator,
368  _ValueType>)
369  __glibcxx_requires_valid_range(__first, __last);
370 
371  if (__first == __last)
372  return __result;
373  _ValueType __value = *__first;
374  *__result = __value;
375  while (++__first != __last)
376  {
377  _ValueType __tmp = *__first;
378  *++__result = __binary_op(__tmp, __value);
379  __value = _GLIBCXX_MOVE(__tmp);
380  }
381  return ++__result;
382  }
383 
384 _GLIBCXX_END_NAMESPACE_ALGO
385 } // namespace std
#define __glibcxx_function_requires(...)
Definition: concept_check.h:47
#define _GLIBCXX_MOVE(__val)
Definition: move.h:145
return(unsigned int) __res
#define __glibcxx_requires_valid_range(_First, _Last)
Definition: debug.h:65