## 6 Indirection ¶

Indirection is the ability to modify or access an array at a set of selected index values. Blitz++ provides several forms of indirection:

- Using a list of array positions: this approach is useful if you need to modify an array at a set of scattered points.
- Cartesian-product indirection: as an example, for a two-dimensional array you might have a list `I` of rows and a list `J` of columns, and you want to modify the array at all (i,j) positions where i is in `I` and j is in `J`. This is a cartesian product of the index sets `I` and `J`.
- Over a set of strips: for efficiency, you can represent an arbitrarily-shaped subset of an array as a list of one-dimensional strips. This is a useful way of handling Regions Of Interest (ROIs).

Three styles of indirection. 4

In all cases, Blitz++ expects a Standard Template Library container. Some useful STL containers are `list<>`, `vector<>`, `deque<>` and `set<>`. Documentation of these classes is often provided with your compiler, or see also the good documentation at http://www.sgi.com/Technology/STL/. STL containers are used because they are widely available and provide easier manipulation of “sets” than Blitz++ arrays. For example, you can easily expand and merge sets which are stored in STL containers; doing this is not so easy with Blitz++ arrays, which are designed for numerical work.

STL containers are generally included by writing

    #include <list>   // for list<>
    #include <vector> // for vector<>
    #include <deque>  // for deque<>
    #include <set>    // for set<>

The `[]` operator is overloaded on arrays so that the syntax `array[container]` provides an indirect view of the array. So far, this indirect view may only be used as an lvalue (i.e. on the left-hand side of an assignment statement).

The examples in the next sections are available in the Blitz++ distribution in `<examples/indirect.cpp>`.

#### Footnotes

##### (4)

From top to bottom: (1) using a list of array positions; (2) Cartesian-product indirection; (3) using a set of strips to represent an arbitrarily-shaped subset of an array.