DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

generate(C++)


generate -- apply a given function to every location in an array

Synopsis

   template <class T>  
   void generate(void (*fun)(ptrdiff_t n,T* p),T* b,T* e);

Assumptions

None.

Description

For each cell in an array from the leftmost to the rightmost, generate calls function fun with two arguments: (1) the cell index (assuming that the index of the first cell is 0) and (2) a pointer to the cell.

Complexity

If N is the size of the array, then complexity is O(N). Exactly N function calls to fun are made.

Example

In the following example, iota assigns a consecutive integer starting from 0 to every location in the array (similar to the APL function iota):

       void zap(ptrdiff_t n, int* address){
           *address = n;
       }
       void iota(int* b, int* e){
           generate(zap, b, e);
       }

Notes

Because a Block (see Block(3C++)) can always be used wherever an array is called for, Array Algorithms can also be used with Blocks. In fact, these two components were actually designed to be used together.

References

Array_alg(C++), Block(C++), fill(C++), for_each(C++), subs(C++)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005