pstade

PrevUpHomeNext

Object Generator

generator
Generating Forms
Deducers

A simple object generator can be built automagically using the following family.

Description

generator is one of the Function Builders which builds an "object generator".

Header
  • <pstade/egg/generator.hpp>
Notation
  • C(Lam) is
  • g is an object of generator<Lam, R0, How, _Stg>::type.
  • X is boost::mpl::apply<C(Lam), _meta_arg_list(a, _Stg)>::type.
  • arglist is _arg_list(a, _Stg).
Valid expressions

Valid expression

Semantics

generator<Lam, R0 = _default, How = _default, _Stg = _default>::type

A Major Function Object POD type

PSTADE_EGG_GENERATOR

A braced initializer of generator<Lam, R0, How, _Stg>::type

g(a1,...,aN)

Returns an object made by How.

g()

Returns a R0 object made by How.

Preconditions
  • Lam is an (possibly cv-qualified) MPL Lambda Expression.
  • 1 <= N && N <= BOOST_MPL_LIMIT_METAFUNCTION_ARITY, which has a default value 5.
  • How is _default or one of the type in Generating Forms.
  • The corresponding semantics is a valid expression.
Invariants
  • Non-local object g with static storage duration is statically initialized if initialized using PSTADE_EGG_GENERATOR.
  • g is Default Constructible and Assignable.
[Note] Note

Lam is not instantiated while invoking boost::mpl::apply, so that any static assertion in generated type doesn't fail.

Example

typedef
    generator<
        std::pair< deduce<boost::mpl::_1, as_value>, deduce<boost::mpl::_2, as_value> >
    >::type
T_make_pair;

T_make_pair const make_pair = PSTADE_EGG_GENERATOR;

void test_generator()
{
    BOOST_CHECK( make_pair(10, std::string("generator"))
        == std::make_pair(10, std::string("generator")) );
}

See also
  • ...
Description

generator generates an object using constructor by default. You need these helpers if a generating type has no constructor.

Header
  • <pstade/egg/use_constructor.hpp> defines use_constructor.
  • <pstade/egg/use_brace1.hpp> defines use_brace1.
  • <pstade/egg/use_brace2.hpp> defines use_brace2.
Notation
Valid expressions

Valid expression

Semantics

use_constructor

return X(arglist);

use_brace1

X x = {arglist}; return x;

use_brace2

X x = {{arglist}}; return x;

See also
  • ...
Description

Egg provides some basic and useful Metafunction Class types for better error messages. You can place any elaborate MPL Lambda Expression in generating type, though.

Header
  • <pstade/egg/generator.hpp>
Valid expressions

Valid expression

Semantics

deduce<A, As>

boost::mpl::apply<As, A> if the corresponding argument is passed; ill-formed otherwise.

deduce<A, As, Def>

boost::mpl::apply<As, A> if the corresponding argument is passed; boost::mpl::identity<Def> otherwise.

as_ref

boost::add_reference<boost::mpl::_>

as_cref

boost::add_reference< boost::add_const<boost::mpl::_> >

as_value

boost::remove_cv< boost::decay<boost::mpl::_> >

as_qualified

boost::mpl::identity<boost::mpl::_>

See also
  • ...
Copyright © 2007 Shunsuke Sogame

PrevUpHomeNext