|
|
template <class T> void generate(void (*fun)(ptrdiff_t n,T* p),T* b,T* e);
None.
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.
If N is the size of the array, then complexity is O(N). Exactly N function calls to fun are made.
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);
}
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.