nview

| Home | Libraries | People | FAQ | More

### nview

##### Description

`nview` presents a view which iterates over a given Sequence in a specified order. An `nview` is constructed from an arbitrary Sequence and a list of indices specifying the elements to iterate over.

##### Header

    #include <boost/fusion/view/nview.hpp>
    #include <boost/fusion/include/nview.hpp>

##### Synopsis

    template <typename Sequence, typename Indices>
    struct nview;

    template <typename Sequence, int I1, int I2 = -1, ...>
    typename result_of::nview<Sequence, I1, I2, ...>::type
    as_nview(Sequence& s);

##### Template parameters

Parameter | Description | Default
--- | --- | ---
`Sequence` | An arbitrary Fusion Forward Sequence |
`Indices` | A `mpl::vector_c<int, ...>` holding the indices defining the required iteration order. |
`I1`, `I2`, `I3`... | A list of integers specifying the required iteration order. | `INT_MAX` for `I2`, `I3`...

##### Model of

- Random Access Sequence (see Sequence Traversal Concept)

Notation

`NV`

  A `nview` type

`s`

  An instance of `Sequences`

`nv1`, `nv2`

  Instances of `NV`

##### Expression Semantics

Semantics of an expression is defined only where it differs from, or is not defined in Random Access Sequence.

Expression | Semantics
--- | ---
`NV(s)` | Creates an `nview` given a sequence and a list of indices.
`NV(nv1)` | Copy constructs an `nview` from another `nview`, `nv1`.
`nv1 = nv2` | Assigns to an `nview`, `nv1`, from another `nview`, `nv2`.

The `nview` internally stores a Fusion `vector` of references to the elements of the original Fusion Sequence

##### Example

    typedef vector<int, char, double> vec;
    typedef mpl::vector_c<int, 2, 1, 0, 2, 0> indices;

    vec v1(1, 'c', 2.0);

    std::cout << nview<vec, indices>(v1) << std::endl; // (2.0 c 1 2.0 1)
    std::cout << as_nview<2, 1, 1, 0>(v1) << std::endl; // (2.0 c c 1)