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

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Front Page / Algorithms / Transformation Algorithms / transform

transform

Synopsis

template<
      typename Seq
    , typename Op
    , typename In = unspecified
    >
struct transform
{
    typedef unspecified type;
};

template<
      typename Seq1
    , typename Seq2
    , typename BinaryOp
    , typename In = unspecified
    >
struct transform
{
    typedef unspecified type;
};

Description

transform is an overloaded name:

[Note: This wording applies to a no-inserter version(s) of the algorithm. See the Expression semantics subsection for a precise specification of the algorithm's details in all cases — end note]

Header

#include <boost/mpl/transform.hpp>

Model of

Reversible Algorithm

Parameters

Parameter Requirement Description
Sequence, Seq1, Seq2 Forward Sequence Sequences to transform.
Op, BinaryOp Lambda Expression A transformation.
In Inserter An inserter.

Expression semantics

The semantics of an expression are defined only where they differ from, or are not defined in Reversible Algorithm.

For any Forward Sequences s, s1 and s2, Lambda Expressions op and op2, and an Inserter in:

typedef transform<s,op,in>::type r; 
Return type:A type.
Postcondition:

Equivalent to

typedef lambda<op>::type f;
typedef lambda<in::operation>::type in_op;

typedef fold< 
      s
    , in::state
    , bind< in_op, _1, bind<f, _2> > 
    >::type r;
typedef transform<s1,s2,op,in>::type r; 
Return type:A type.
Postcondition:

Equivalent to

typedef lambda<op2>::type f;
typedef lambda<in::operation>::type in_op;

typedef fold< 
      pair_view<s1,s2>
    , in::state
    , bind< 
          in_op
        , _1
        , bind<f, bind<first<>,_2>, bind<second<>,_2> >
        > 
    >::type r;

Complexity

Linear. Exactly size<s>::value / size<s1>::value applications of op / op2 and in::operation.

Example

typedef vector<char,short,int,long,float,double> types;
typedef vector<char*,short*,int*,long*,float*,double*> pointers;
typedef transform< types,boost::add_pointer<_1> >::type result;

BOOST_MPL_ASSERT(( equal<result,pointers> ));

See also

Transformation Algorithms, Reversible Algorithm, reverse_transform, copy, replace_if