DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

numeric(C++std)


accumulate , adjacent_difference , inner_product , partial_sum - defines several templates that implement useful numeric functions (standard template library)

Synopsis

   namespace std {
   template<class InIt, class T>
       T accumulate(InIt first, InIt last, T val);
   template<class InIt, class T, class Pred>
       T accumulate(InIt first, InIt last, T val, Pred pr);
   template<class InIt1, class InIt2, class T>
       T inner_product(InIt1 first1, InIt1 last1,
           Init2 first2, T val);
   template<class InIt1, class InIt2, class T,
       class Pred1, class Pred2>
       T inner_product(InIt1 first1, InIt1 last1,
           Init2 first2, T val, Pred1 pr1, Pred2 pr2);
   template<class InIt, class OutIt>
       OutIt partial_sum(InIt first, InIt last,
           OutIt result);
   template<class InIt, class OutIt, class Pred>
       OutIt partial_sum(InIt first, InIt last,
           OutIt result, Pred pr);
   template<class InIt, class OutIt>
       OutIt adjacent_difference(InIt first, InIt last,
           OutIt result);
   template<class InIt, class OutIt, class Pred>
       OutIt adjacent_difference(InIt first, InIt last,
           OutIt result, Pred pr);
       };

Description

Include the STL standard header <numeric> to define several template functions useful for computing numeric values. The descriptions of these templates employ a number of conventions common to all algorithms.

accumulate

   template<class InIt, class T>
       T accumulate(InIt first, InIt last, T val);
   template<class InIt, class T, class Pred>
       T accumulate(InIt first, InIt last, T val, Pred pr);

The first template function repeatedly replaces val with val + *I, for each value of the InIt iterator I in the interval [first, last). It then returns val.

The second template function repeatedly replaces val with pr(val, *I), for each value of the InIt iterator I in the interval [first, last). It then returns val.

adjacent_difference

   template<class InIt, class OutIt>
       OutIt adjacent_difference(InIt first, InIt last,
           OutIt result);
   template<class InIt, class OutIt, class Pred>
       OutIt adjacent_difference(InIt first, InIt last,
           OutIt result, Pred pr);

The first template function stores successive values beginning at result, for each value of the InIt iterator I in the interval [first, last). The first value val stored (if any) is *I. Each subsequent value stored is *I - val, and val is replaced by *I. The function returns result incremented last - first times.

The second template function stores successive values beginning at result, for each value of the InIt iterator I in the interval [first, last). The first value val stored (if any) is *I. Each subsequent value stored is pr(*I, val), and val is replaced by *I. The function returns result incremented last - first times.

inner_product

   template<class InIt1, class InIt2, class T>
       T inner_product(InIt1 first1, InIt1 last1,
           Init2 first2, T val);
   template<class InIt1, class InIt2, class T,
       class Pred1, class Pred2>
       T inner_product(InIt1 first1, InIt1 last1,
           Init2 first2, T val, Pred1 pr1, Pred2 pr2);

The first template function repeatedly replaces val with val + (*I1 * *I2), for each value of the InIt1 iterator I1 in the interval [first1, last2). In each case, the InIt2 iterator I2 equals first2 + (I1 - first1). The function returns val.

The first template function repeatedly replaces val with pr1(val, pr2(*I1, *I2)), for each value of the InIt1 iterator I1 in the interval [first1, last2). In each case, the InIt2 iterator I2 equals first2 + (I1 - first1). The function returns val.

partial_sum

   template<class InIt, class OutIt>
       OutIt partial_sum(InIt first, InIt last,
           OutIt result);
   template<class InIt, class OutIt, class Pred>
       OutIt partial_sum(InIt first, InIt last,
           OutIt result, Pred pr);

The first template function stores successive values beginning at result, for each value of the InIt iterator I in the interval [first, last). The first value val stored (if any) is *I. Each subsequent value val stored is val + *I. The function returns result incremented last - first times.

The second template function stores successive values beginning at result, for each value of the InIt iterator I in the interval [first, last). The first value val stored (if any) is *I. Each subsequent value val stored is pr(val, *I). The function returns result incremented last - first times.

References


18 February 2000
© 2000 The Santa Cruz Operation, Inc. All rights reserved.

Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.