for_each

| Home | Libraries | People | FAQ | More

##### for_each

###### Prototype

    template<
        class SinglePassRange1,
        class SinglePassRange2,
        class BinaryFunction
        >
    BinaryFunction for_each(const SinglePassRange1& rng1,
                            const SinglePassRange2& rng2,
                            BinaryFunction fn);

    template<
        class SinglePassRange1,
        class SinglePassRange2,
        class BinaryFunction
        >
    BinaryFunction for_each(const SinglePassRange1& rng1,
                            SinglePassRange2& rng2,
                            BinaryFunction fn);

    template<
        class SinglePassRange1,
        class SinglePassRange2,
        class BinaryFunction
        >
    BinaryFunction for_each(SinglePassRange1& rng1,
                            const SinglePassRange2& rng2,
                            BinaryFunction fn);

    template<
        class SinglePassRange1,
        class SinglePassRange2,
        class BinaryFunction
        >
    BinaryFunction for_each(SinglePassRange1& rng1,
                            SinglePassRange2& rng2,
                            BinaryFunction fn);

###### Description

`for_each` traverses forward through `rng1` and `rng2` simultaneously. For each iteration, the element `x` is used from `rng1` and the corresponding element `y` is used from `rng2` to invoke `fn(x,y)`.

Iteration is stopped upon reaching the end of the shorter of `rng1`, or `rng2`. It is safe to call this function with unequal length ranges.

###### Definition

Defined in the header file `boost/range/algorithm_ext/for_each.hpp`

###### Requirements

1. `SinglePassRange1` is a model of the Single Pass Range Concept.
2. `SinglePassRange2` is a model of the Single Pass Range Concept.
3. `BinaryFunction` is a model of the `BinaryFunctionConcept`.
4. `SinglePassRange1`'s value type is convertible to `BinaryFunction`'s first argument type.
5. `SinglepassRange2`'s value type is convertible to `BinaryFunction`'s second argument type.

###### Complexity

Linear. Exactly `min(distance(rng1), distance(rng2))` applications of `BinaryFunction`.