Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext
transform
Prototype

template<
    class SinglePassRange1,
    class OutputIterator,
    class UnaryOperation
>
OutputIterator transform(const SinglePassRange1& rng,
                         OutputIterator out,
                         UnaryOperation fun);

template<
    class SinglePassRange1,
    class SinglePassRange2,
    class OutputIterator,
    class BinaryOperation
>
OutputIterator transform(const SinglePassRange1& rng1,
                         const SinglePassRange2& rng2,
                         OutputIterator out,
                         BinaryOperation fun);

Description

UnaryOperation version:

transform assigns the value y to each element [out, out + distance(rng)), y = fun(x) where x is the corresponding value to y in rng1. The return value is out + distance(rng).

BinaryOperation version:

transform assigns the value z to each element [out, out + min(distance(rng1), distance(rng2))), z = fun(x,y) where x is the corresponding value in rng1 and y is the corresponding value in rng2. This version of transform stops upon reaching either the end of rng1, or the end of rng2. Hence there isn't a requirement for distance(rng1) == distance(rng2) since there is a safe guaranteed behaviour, unlike with the iterator counterpart in the standard library.

The return value is out + min(distance(rng1), distance(rng2)).

Definition

Defined in the header file boost/range/algorithm/transform.hpp

Requirements

For the unary versions of transform:

For the binary versions of transform:

Precondition:

For the unary version of transform:

For the binary version of transform:

Complexity

Linear. The operation is applied exactly distance(rng1) for the unary version and min(distance(rng1), distance(rng2)) for the binary version.


PrevUpHomeNext