It is difficult or even impossible to get a Function Object from a function template. Egg no longer considers function templates to be useful, so that it provides "objectified" functions which replace some famous function templates. Note that a Function Object type defined in this section is Default Constructible and Copy Assignable unless otherwise specified.
adapted_to
provides the way
to access underlying "base" Function
Object or Little
Function from adapted Function
Object.
<boost/egg/adapted_to.hpp>
b
is a "base"
object such that __decltype
(b)
is
B const
&
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
Extracts |
|
|
f
is a Function
Object which Function
Adaptors or Function
Builders build.
B
is a "base"
Function Object
or Little Function
type.
struct base_plus { int id; typedef int result_type; result_type operator()(int x, int y) const { return x + y; } }; typedef result_of_curry2<base_plus>::type T_curried_plus; T_curried_plus const curried_plus777 = BOOST_EGG_CURRY2({777}); T_curried_plus const curried_plus999 = BOOST_EGG_CURRY2({999}); bool operator==(T_curried_plus const &left, T_curried_plus const &right) { return egg::adapted_to<base_plus>(left).id == egg::adapted_to<base_plus>(right).id; } void egg_example() { BOOST_CHECK( curried_plus777(4)(9) == 4+9 ); BOOST_CHECK( egg::adapted_to<base_plus>(curried_plus777).id == 777); BOOST_CHECK( curried_plus777 == curried_plus777 ); BOOST_CHECK(!(curried_plus777 == curried_plus999) ); }
always
returns a Function
Object always returning the same object.
<boost/egg/always.hpp>
bound(x)
is
__fwd_arg_list
([x], by_value)
.
Valid expression |
Semantics |
---|---|
|
A Major
Function Object which holds |
|
|
|
|
|
|
|
|
0 <=
N &&
N <=
BOOST_EGG_MAX_LINEAR_ARITY
.
__typeof
(x)
is Copy Constructible.
void egg_example() { int ten = 10; BOOST_CHECK( always(ten)(1,2,3,4,5) == 10 ); BOOST_CHECK( &(always_ref(ten)(1,2,3,4,5)) == &ten ); }
identity
returns argument
unchanged.
<boost/egg/identity.hpp>
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
|
void egg_example() { BOOST_CHECK( identity(10) == 10 ); }
apply
calls a function with
trailing arguments.
<boost/egg/apply.hpp>
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
|
__fwd_arg_list
([__pfo
,a1,...,aN], __Stg
)
is a valid expression.
void egg_example() { std::negate<int> my_negate; BOOST_CHECK( apply(my_negate, apply(my_negate, apply(my_negate, 10))) == -10 ); }
bll_N
is a Lexically
Typed Object which represents boost::lambda::_N
.
Caution | |
---|---|
|
<boost/egg/bll/placeholders.hpp>
Valid expression |
Semantics |
---|---|
|
Polymorphic
|
boost::remove_reference<__decltype
(bll_%%N)>::type
is T_bll_%%N const
.
boost::result_of<T_bll_%%N const(a1,...,aK)>::type
is the same as boost::result_of<T_bll_%%N(a1,...,aK)>::type
.
void egg_example() { std::plus<int> plus; result_of_< result_of_<T_lazy(std::plus<int> &)>::type(T_bll_1 const &, int) >::type f = lazy(plus)(bll_1, 10); int i2 = 2; BOOST_CHECK( f(i2) == 12 ); }
X_construct
is constructor
as Function Object.
<boost/egg/construct.hpp>
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
void egg_example() { BOOST_CHECK( apply(X_construct<int>(), 3) == 3 ); }
X_construct_braced1
constructs
object using braced-initializer.
<boost/egg/construct_braced1.hpp>
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
X_construct_braced2
constructs
object using braced-initializer.
<boost/egg/construct_braced2.hpp>
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
X_construct_variadic1
constructs
variadic
object using braced-initializer.
<boost/egg/construct_variadic1.hpp>
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
get
returns the N-th element
from the beginning of the Fusion
Forward Sequence.
<boost/egg/get.hpp>
fusion
is boost::fusion
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
|
|
|
|
void egg_example() { typedef std::map<std::string, int> map_t; map_t m; m["one"] = 1; m["two"] = 2; int a[] = {1,2}; boost::transform_iterator<X_get_c<1>, map_t::iterator, int &> it(m.begin(), X_get_c<1>()); BOOST_CHECK(std::equal(a, a+2, it)); }
pack
makes boost::tuple<...>
for argument forwarding.
<boost/egg/pack.hpp>
dts_(c1,...,cK)
is
__decltype
(c1),...,__decltype
(cK)
.
Valid expression |
Semantics |
---|---|
A Major Function Object type |
|
|
|
|
|
__bytag_at
(__Stg
, N,
I)
is by_value
, __typeof
(aI)
is Copy Constructible.
void egg_example() { BOOST_CHECK( boost::get<1>(pack(1,'1',std::string("one"))) == '1' ); }