Function builders build Major
Function Object type, which can be used with boost::lambda::bind
and
boost::result_of
.
function
is the "kernel"
class template which builds a Little
Function into Major
Function Object type.
<pstade/egg/function.hpp>
template<class Little, class Stg = _default> struct function { typedef Little little_type; typedef function function_type; Little lit; // exposition only Little little() const { return lit; } // unspecified // ... };
f
is an object of function<_Lit, _Stg>
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object aggregate type |
|
|
|
|
function<_Lit, _Stg>
is a POD type if and only if _Lit
is a POD type.
function<_Lit, _Stg>
is Default
Constructible if and only if _Lit
is Default
Constructible.
function<_Lit, _Stg>
is Assignable
if and only if _Lit
is
Assignable.
struct little_second_argument { template<class Myself, class A1, class A2> struct apply { typedef A2 &type; }; template<class Result, class A1, class A2> Result call(A1 &a1, A2 &a2) const { return a2; } }; typedef function<little_second_argument, by_perfect> T_second_argument; T_second_argument const second_argument = {{}}; void test_function() { int i = 2; BOOST_CHECK( &(second_argument(1, i)) == &i ); BOOST_CHECK( second_argument(1, i) == 2 ); }
|
|
|
|
A braced initialization is ok, because |
function_facade
creates a
new Major Function Object
type using "CRTP". Though a type built from function_facade
can't be a POD type, it can have non-default constructors.
<pstade/egg/function_facade.hpp>
Valid expression |
Semantics |
---|---|
|
|
|
|
|
|
_lit
is an object whose
type is derived from function_facade<_typeof(_lit), R0 = _default, _Stg = _default>
.
template<class T> struct plus_to : function_facade< plus_to<T> > { template<class Myself, class A> struct apply { typedef T type; }; template<class Result, class A> Result call(A &a) const { return m_x + a; } explicit plus_to(T x) : m_x(x) {} private: T m_x; }; template<class T> plus_to<T> make_plus_to(T x) { return plus_to<T>(x); } void test_function_facade() { BOOST_CHECK( make_plus_to(1)(3) == 4 ); }
deferred
is akin to boost::detail::functionN
family. It is useful because
operator()
can use nested typedefs.
<pstade/egg/deferred.hpp>
f
is an object of deferred<Lam, _Stg>::type
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object POD type |
|
A braced initializer of |
|
|
Lam
is an MPL
Lambda Expression which is neither reference
nor cv-qualified.
1 <=
N &&
N <=
BOOST_MPL_LIMIT_METAFUNCTION_ARITY
,
which has a default value 5
.
boost::mpl::apply<Lam, _meta_arg_list(a, _Stg)>::type::result_type
is a valid expression.
f
with
static storage duration is statically initialized
if initialized using PSTADE_EGG_DEFERRED
.
f
is Default
Constructible and Assignable.
Caution | |
---|---|
For some compiler bug,
|
template<class X> struct base_my_identity { typedef X &result_type; result_type operator()(X &x) const { return x; } }; typedef deferred< base_my_identity<boost::mpl::_1> >::type T_my_identity; T_my_identity const my_identity = PSTADE_EGG_DEFERRED;
See Object Generator section.
automatic
adds automatic
conversion support to a cast form function.
<pstade/egg/automatic.hpp>
u
is an object of automatic<Lam, _Stg>::type
.
f
is an object of boost::mpl::apply<Lam, _typeof(to)>::type
.
Valid expression |
Semantics |
---|---|
|
A Major Function Object POD type |
|
A braced initializer of |
|
|
0 <=
N &&
N <=
_TUPLE_MAX_SIZE
.
Lam
is an MPL
Lambda Expression which is neither reference
nor cv-qualified.
f
is a Polymorphic
Function Object.
X_
such
that boost::is_convertible<X_, _typeof(to)>::value == false
.
u
is not placed in a default
argument list.
Note | |
---|---|
These valid expressions imply that the automatic deduction is available
everywhere copy-initialization is invoked. For example,
you can place
|
u
with
static storage duration is statically initialized
if initialized using PSTADE_EGG_AUTOMATIC
.
u
is Default
Constructible and Assignable.
template<class To> struct X_lexical_cast { typedef To result_type; template<class From> To operator()(From from) const { return boost::lexical_cast<To>(from); } }; typedef automatic< X_lexical_cast<boost::mpl::_> >::type T_lexicalize; T_lexicalize const lexicalize = PSTADE_EGG_AUTOMATIC; void test_automatic() { std::string str = lexicalize(20); BOOST_CHECK( str == "20" ); }
make_function
is the object
generator of function<>
.
This is useful when you need a "self" Major
Function Object in Little
Functioncall
.
<pstade/egg/make_function.hpp>
Valid expression |
Semantics |
---|---|
|
A Major Function Object type |
|
|
|
|
...
Copyright © 2007 Shunsuke Sogame |