...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
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
.
template<
typename Sequence,
typename F
>
typename result_of::transform
<Sequence const, F>::type transform(
Sequence const& seq, F f);
Table 1.75. Parameters
Parameter 
Requirement 
Description 


A model of Forward Sequence 
Operation's argument 


Transformation function 
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
.
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.76. Parameters
Parameter 
Requirement 
Description 


A model of Forward Sequence 
Operation's argument 

A model of Forward Sequence 
Operation's argument 


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.
Constant. Returns a view which is lazily evaluated.
#include <boost/fusion/algorithm/transformation/transform.hpp> #include <boost/fusion/include/transform.hpp>
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));