![]() |
Home | Libraries | People | FAQ | More |
An n-ary Polymorphic Function Object adapter template for an unary Polymorphic Function Object target function. When called, its arguments are bundled to a Random Access Sequence that is passed to the target function object.
The call operators of the resulting function object are strictly typed (in other words, non-templatized) with the types from a Sequence. By default, call operators with zero to N parameters are generated to, where N is the size of the Sequence that specifies the types.
The overload set of the adapter's function call operator can be restricted
by removing the type member
from the nested result metafunction of the Polymorphic
Function Object (in this case the substitution-failure-is-not-an-error
principle applies for non-nullary calls and nullary calls are explicitly
disabled by the library).
![]() |
Caution |
|---|---|
As the function call operators are not templates, they are instantiated along with the class template, so they must be disabled (as described above) in cases where they are not instantiable. |
The type of the target function is allowed to be const qualified or a reference.
Const qualification is preserved and propagated appropriately (in other
words, only const versions of operator() can be used
if the target function object is const - or, in case the target function
object is held by value, the adapter is const).
![]() |
Tip |
|---|---|
If the type sequence passed to this template contains non-reference elements, the element is copied only once - the call operator's signature is optimized automatically to avoid by-value parameters. |
#include <boost/fusion/functional/adapter/unfused_typed.hpp>
template <class Function, class Sequence> class unfused_typed;
| Parameter | Description | Default |
|---|---|---|
Function |
A unary Polymorphic Function Object | |
Sequence |
A Sequence |
Notation
FfF
SUTunfused_typed<F,S>
utUT, initialized
with f
a0...aNut, convertible
to the types in S
| Expression | Semantics |
|---|---|
UT(f) |
Creates
a fused function as described above, initializes the target function
with f. |
UT() |
Creates
a fused function as described above, attempts to use F's default constructor. |
ut(a0...aN)
|
Calls f with an instance of S (or a subsequence of S starting at the first element,
if fewer arguments are given and the overload hasn't been disabled)
initialized with a0...aN. |
struct add_assign // applies operator+= { typedef void result_type; // for simplicity template <typename T> void operator()(T & lhs, T const & rhs) const { lhs += rhs; } }; template <class Tie> class fused_parallel_adder { Tie tie_dest; public: explicit fused_parallel_adder(Tie const & dest) : tie_dest(dest) { } template <class Seq> struct result { typedef void type; }; template <class Seq> void operator()(Seq const & s) const {for_each(zip(tie_dest,s),fused<add_assign>() ); } }; // accepts a tie and creates a typed function object from it struct fused_parallel_adder_maker { template <class Seq> struct result { typedef unfused_typed<fused_parallel_adder<Seq>, typename mpl::transform<Seq, remove_reference<_> >::type > type; }; template <class Seq> typename result<Seq>::type operator()(Seq const & tie) { return typename result<Seq>::type(fused_parallel_adder<Seq>(tie)); } };unfused_lvalue_args<fused_parallel_adder_maker> parallel_add; int main() { int a = 2; char b = 'X'; // the second call is strictly typed with the types deduced from the // first call parallel_add(a,b)(3,2); parallel_add(a,b)(3); parallel_add(a,b)(); assert(a == 8 && b == 'Z'); return 0; }
| Copyright © 2001-2007 Joel de Guzman, Dan Marsden, Tobias Schwinger |