.\" ident @(#)Array_alg:man/generate.3 3.2 .\" .\" C++ Standard Components, Release 3.0. .\" .\" Copyright (c) 1991, 1992 AT&T and UNIX System Laboratories, Inc. .\" Copyright (c) 1988, 1989, 1990 AT&T. All Rights Reserved. .\" .\" THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T and UNIX System .\" Laboratories, Inc. The copyright notice above does not evidence .\" any actual or intended publication of such source code. .\" .TH \f3generate\fP \f3Array_alg(3C++)\fP " " .SH NAME generate \- apply a given function to every location in an array .SH SYNOPSIS OF Array_alg.h .Bf #include template void generate(void (*fun)(ptrdiff_t n,\*(gt* p),\*(gt* b,\*(gt* e); .Be .SH ASSUMPTIONS None. .SH DESCRIPTION .PP For each cell in an array from the leftmost to the rightmost, \f4generate\f1 calls function \f4fun\f1 with two arguments: (1) the cell index (assuming that the index of the first cell is \f20\f1) and (2) a pointer to the cell. .SH COMPLEXITY .PP If \f2N\f1 is the size of the array, then complexity is \f2O(N)\f1. Exactly \f2N\f1 function calls to \f4fun\f1 are made. .SH EXAMPLE .PP In the following example, \f4iota\f1 assigns a consecutive integer starting from \f20\f1 to every location in the array (similar to the APL function \f4iota\f1): .Bf void zap(ptrdiff_t n, int* address){ *address = n; } void iota(int* b, int* e){ generate(zap, b, e); } .Be .SH NOTES Because a Block (see \f3Block(3C++)\f1) 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. .SH SEE ALSO .Bf \f3intro(.)\f1 \f3fill(.)\f1 \f3for_each(.)\f1 \f3subs(.)\f1 \f3Block(3C++)\f1 .Be