Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext
transform
Description

For a sequence seq and function object or function pointer f, transform returns a new sequence with elements created by applying f(e) to each element of e of seq.

Unary version synopsis
template<
    typename Sequence,
    typename F
    >
typename result_of::transform<Sequence const, F>::type transform(
    Sequence const& seq, F f);

Table 1.68. Parameters

Parameter

Requirement

Description

seq

A model of Forward Sequence

Operation's argument

f

f(e) is a valid expression for each element e of seq. boost::result_of<F(E)>::type is the return type of f when called with a value of each element type E.

Transformation function


Expression Semantics
transform(seq, f);

Return type: A model of Forward Sequence

Semantics: Returns a new sequence, containing the return values of f(e) for each element e within seq.

Binary version synopsis
template<
    typename Sequence1,
    typename Sequence2,
    typename F
    >
typename result_of::transform<Sequence1 const, Sequence2 const, F>::type transform(
    Sequence1 const& seq1, Sequence2 const& seq2, F f);

Table 1.69. Parameters

Parameter

Requirement

Description

seq1

A model of Forward Sequence

Operation's argument

seq2

A model of Forward Sequence

Operation's argument

f

f(e1,e2) is a valid expression for each pair of elements e1 of seq1 and e2 of seq2. boost::result_of<F(E1,E2)>::type is the return type of f when called with elements of type E1 and E2

Transformation function


Return type: A model of Forward Sequence.

Semantics: Returns a new sequence, containing the return values of f(e1, e2) for each pair of elements e1 and e2 within seq1 and seq2 respectively.

Complexity

Constant. Returns a view which is lazily evaluated.

Header
#include <boost/fusion/algorithm/transformation/transform.hpp>
#include <boost/fusion/include/transform.hpp>
Example
struct triple
{
    typedef int result_type;

    int operator()(int t) const
    {
        return t * 3;
    };
};
...
assert(transform(make_vector(1,2,3), triple()) == make_vector(3,6,9));

PrevUpHomeNext