![]() |
Function Adaptor is a higher-order function that takes a "base" Function Object and returns an "adapted" Function Object. Function Adaptor provides, if possible, two interfaces: A normal higher-order Function Object, and a Metafunction with the corresponding macro for static initialization. An adapted non-local Function Object with static storage duration is statically initialized if the base Function Object type is a POD type and an expression passed to the macro is a constant expression. Also, Function Adaptors don't modify Default Constructible and Assignable-ness of base Function Object unless otherwise specified.
![]() |
Note |
|---|---|
|
If a macro argument is not guaranteed to contain no commas and recursions,
you must use
|
ambi family helps you to
makes an Ambi Function
Object.
<pstade/egg/ambi.hpp>fc(d) is
an object of result_of_ambi++N<_typeof(d)>::type initialized using d or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
An Ambi Major Function Object type. |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
1 <=
N &&
N <=
PSTADE_EGG_MAX_ARITY.
d_ such that
_PFo d_
= init; is a valid expression.
result_of_ambi++N<_PFo>::type is a POD type
if and only if _PFo is
a POD type.
struct base_my_plus { typedef int result_type; int operator()(int x, int y) const { return x + y; } }; typedef result_of_ambi2<base_my_plus>::type T_my_plus; T_my_plus const my_plus = PSTADE_EGG_AMBI({}); void test_ambi() { BOOST_CHECK( my_plus(1, 2) == 3 ); BOOST_CHECK( ( 1|my_plus(2) ) == 3 ); std::plus<int> std_plus; BOOST_CHECK( ambi2(std_plus)(1, 2) == 3); BOOST_CHECK( ( 1|ambi2(std_plus)(2) ) == 3); }
compose is a Function Adaptor
for function composition.
<pstade/egg/compose.hpp>fc(d1, d2, R0, _Stg)
is an object of result_of_compose<_typeof(d1),_typeof(d2), R0, _Stg>::type initialized using d1 and d1
or these initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
A Major Function Object type |
|
|
|
|
|
|
0 <=
N &&
N <=
_TUPLE_MAX_SIZE.
d1_ and d2_ such that _Dco1
d1_ =
init1;
_Dco2 d2_
= init2; is a valid expression.
_deduce_r0(R0, d1(d2())) is a valid expression which specifies
the nullary return type.
![]() |
Note |
|---|---|
|
The last precondition means that
|
result_of_compose<_Dco1, _Dco2, R0, _Stg>::type is a POD type
if and only if _Dco1 and
_Dco2 is a POD
type.
...
curry family turns a base
Function Object
into curried one.
<pstade/egg/curry.hpp>fc(d) is
an object of result_of_curry++N<_typeof(d)>::type initialized using d or an initializer.
b is a1,...,a(N-1).
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
N is the arity of _PFo such that 2
<= N
&& N
<= PSTADE_EGG_MAX_ARITY.
d_ such that
_PFo d_
= init; is a valid expression.
result_of_curry++N<_PFo>::type is a POD type
if and only if _PFo is
a POD type.
![]() |
Note |
|---|---|
|
An element of
|
typedef result_of_curry2<T_my_plus>::type T_curried_plus; T_curried_plus const curried_plus = PSTADE_EGG_CURRY2_L PSTADE_EGG_AMBI({}) PSTADE_EGG_CURRY2_R; void test_curry() { BOOST_CHECK( curried_plus(4)(9) == my_plus(4, 9) ); BOOST_CHECK( curry2(my_plus)(4)(9) == 13 ); }
uncurry reverses curry.
<pstade/egg/uncurry.hpp>fc(d, _Stg) is an object of result_of_uncurry<_typeof(d),
_Stg>::type initialized using d or an initializer.
parens(b1,...,bN) is
(b1)(b2),...,(bN).
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
2 <=
N &&
N <=
PSTADE_EGG_MAX_ARITY.
d_ such that
_PFo d_
= init; is a valid expression.
result_of_uncurry<_PFo>::type is a POD type
if and only if _PFo is
a POD type.
fuse converts the base Function Object into
a unary Function Object
which takes a tuple.
<pstade/egg/fuse.hpp>fc(d) is
an object of result_of_fuse<_typeof(d)>::type initialized using d or an initializer.
t_ is _arg_list(t,
by_perfect).
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
|
|
|
1 <=
N &&
N <=
_TUPLE_MAX_SIZE.
d_ such that
_PFo d_
= init; is a valid expression.
t0 is an empty tuple.
result_of_fuse<_PFo>::type is a POD type
if and only if _PFo is
a POD type.
unfuse reverses fuse.
<pstade/egg/unfuse.hpp>fc(d, R0, _Stg) is an object of result_of_unfuse<_typeof(d),
_default,
R0,
_Stg>::type initialized using d or an initializer.
ref(b1,...,bN) is
b1&,...,bN&.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 <=
N &&
N <=
_TUPLE_MAX_SIZE.
d_ such that
_PFo d_
= init; is a valid expression.
_deduce_r0(R0, _decltype(d( boost::tuple<>() ))
is a valid expression which specifies the nullary return type.
result_of_unfuse<_PFo>::type is a POD type
if and only if _PFo is
a POD type.
...
indirect takes a pointer-like
object then calls it after dereferencing.
<pstade/egg/indirect.hpp>fc(p, _Stg) is an object of result_of_indirect<_typeof(p),
_Stg>::type initialized using p or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
boost::pointee<Pco>::type is Polymorphic
Function Object type.
p_ such that
Pco p_
= init; is a valid expression.
result_of_indirect<Pco, _Stg>::type is a POD type
if and only if Pco is a
POD type.
result_of_uncurry< result_of_indirect<T_curried_plus const *>::type >::type const another_plus = PSTADE_EGG_UNCURRY_LPSTADE_EGG_INDIRECT(&curried_plus) PSTADE_EGG_UNCURRY_R ;
|
|
Boost.Phoenix
is able to make a lambda expression without a "bind function".
lazy turns a bindable Function Object into
such one which can be used with Boost.Lambda.
<pstade/egg/lazy.hpp>fc(f) is
an object of result_of_lazy<_typeof(f)>::type initialized using f or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
Polymorphic
|
|
|
|
0 <=
N &&
N <=
PSTADE_EGG_MAX_LINEAR_ARITY-1.
f_ such that
F f_
= init; is a valid expression.
result_of_lazy<F>::type is a POD type
if and only if F is a
POD type.
result_of_lazy<base_my_plus>::type const my_Plus = PSTADE_EGG_LAZY({}); void test_lazy() { namespace bll = boost::lambda;BOOST_CHECK( my_Plus(bll::_1, 3)(bll::make_const(2)) == 2+3 ); int two = 2, four = 4; BOOST_CHECK( my_Plus(my_Plus(bll::_1, 3), my_Plus(bll::_2, bll::_1)) (two, four) == (2+3)+(4+2) ); }
memoize stores the result
of function for later reuse.
<pstade/egg/memoize.hpp>fixed is an unspecified
unary Function Object
which represents _pfo itself.
|
Valid expression |
Semantics |
|---|---|
|
|
|
|
|
|
![]() |
Note |
|---|---|
|
|
memoize(_pfo)
must always be called with the same type arguments.
_typeof(a1) is
Assignable,
Copy Constructible
and Equality
Comparable.
_decltype(
_pfo(fixed, _arg_list(a, by_cref)) ) is
Copy Constructible.
struct T_fib { typedef int result_type; template<class Fixed> int operator()(Fixed f, int x) const { return x <= 1 ? 1 : f(x-1) + f(x-2); } int operator()(int x) const { return (*this)(*this, x); } }; T_fib const fib = {}; void test_memoize() { BOOST_CHECK( fib(30) == 1346269 ); BOOST_CHECK( memoize(fib)(30) == 1346269 ); }
mono turns a base Function Object into
"monomorphic" one which contains no templates.
<pstade/egg/mono.hpp>fc(f) is
an object of result_of_mono<_typeof(f),
Sig>::type initialized using f or an initializer.
N is an arity of Sig.
R is a return type of
Sig.
ParamOf(Sig, I) is
an imaginary operator which returns an Ith
parameter type of Sig.
arglist is b1,...,bN such that ParamOf(Sig, 0)
b1 =
a1;
... ParamOf(Sig, N-1) bN
= aN;.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
A Major Function Object type |
|
|
|
|
|
|
Fun is a Function
Object type.
Sig is a function
type.
f_ such that
Fun f_
= init; is a valid expression.
R is _default,
Fun is a Polymorphic
Function Object type; R
specifies a return type of Fun,
otherwise.
result_of_mono<Fun, Sig>::type is a POD type
if and only if Fun is a
POD type.
result_of_mono<Fun, Sig>::type is Adaptable
if and only if N is 1 or 2.
BOOST_CHECK( std::not1( egg::mono<bool(int)>(bll::_1 != 12) ) (12) ); BOOST_CHECK( std::bind1st( egg::mono<boost::use_default(int, int)>(bll::_1 == bll::_2), 12 ) (12) );
perfect performs the "perfect
forwarding".
<pstade/egg/perfect.hpp>fc(d) is
an object of result_of_perfect<_typeof(d)>::type initialized using d or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
d_ such that
_PFo d_
= init; is a valid expression.
result_of_perfect<_PFo>::type is a POD type
if and only if _PFo is
a POD type.
BOOST_CHECK( perfect(boost::lambda::_1)(12) == 12 );
pipable adapts a base Function Object into
Pipable Function Object.
<pstade/egg/pipable.hpp>fc(d, _Stg) is an object of result_of_pipable<_typeof(d),
_Stg>::type initialized using d or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Pipable Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
1 <=
N &&
N <=
_TUPLE_MAX_SIZE-1.
d_ such that
_PFo d_
= init; is a valid expression.
result_of_pipable<_PFo, _Stg>::type is a POD type
if and only if _PFo is
a POD type.
struct base_multiplies { typedef int result_type; int operator()(int x) const { return x * x; } int operator()(int x, int y) const { return x * y; } int operator()(int x, int y, int z) const { return x * y * z; } }; result_of_pipable<base_multiplies>::type const multiplies = PSTADE_EGG_PIPABLE({}); void test_pipable() { BOOST_CHECK( ( 2|multiplies ) == 2 * 2 ); BOOST_CHECK( ( 2|multiplies() ) == 2 * 2 ); BOOST_CHECK( ( 2|multiplies(3)|multiplies(4) ) == 2 * 3 * 4 ); BOOST_CHECK( ( 2|multiplies(3, 4) ) == 2 * 3 * 4 ); // `|=` seems an "apply" operator. BOOST_CHECK( ( multiplies|=2 ) == 2 * 2 ); BOOST_CHECK( ( multiplies()|=2 ) == 2 * 2 ); BOOST_CHECK( ( multiplies|=multiplies|=2) == (2 * 2) * (2 * 2) ); BOOST_CHECK( ( multiplies(3)|=2 ) == 2 * 3 ); BOOST_CHECK( ( multiplies(3, 4)|= 2 ) == 2 * 3 * 4 ); }
A Boost.Lambda functor
is neither Default
Constructible nor Assignable.
An iterator holding such a functor can't conform to even Input
Iterator. regular
converts it into comfortable one for iterators.
<pstade/egg/regular.hpp>|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object which is Default Constructible and Assignable. |
|
|
|
f is a Boost.Lambda
functor or Polymorphic
Function Object.
...
ret is akin to boost::lambda::ret in the context of Boost.ResultOf.
<pstade/egg/ret.hpp>fc(f, R, _Stg) is an object of result_of_ret<_typeof(f),
R,
_Stg>::type initialized using f or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
A Major Function Object type |
|
|
|
|
|
|
Fun is a Function
Object type.
Fun is a Polymorphic
Function Object type if R
is _default.
f_ such that
Fun f_
= init; is a valid expression.
result_of_ret<Fun, R, _Stg>::type
is a POD type if and only if Fun
is a POD type.
...
tagged makes a new Function Object type.
<pstade/egg/tagged.hpp>fc(d, Tag, _Stg) is an object of result_of_tagged<_typeof(d),
Tag,
_Stg>::type initialized using d or an initializer.
|
Valid expression |
Semantics |
|---|---|
|
|
A Major Function Object type |
|
|
A braced initializer of |
|
|
|
|
|
|
|
|
|
|
|
|
Tag is any (possibly incomplete)
type.
d_ such that
_PFo d_
= init; is a valid expression.
result_of_tagged<_PFo, Tag, _Stg>::type is a POD type
if and only if _PFo is
a POD type.
result_of_tagged<_PFo, Tag1, _Stg>::type is the same type as result_of_tagged<_PFo, Tag2, _Stg>::type if and only if Tag1
is the same type as Tag2.
...
| Copyright © 2007 Shunsuke Sogame |