Boost C++ Libraries

PrevUpHomeNext

Function Objects

adapted_to
always
identity
apply
bll_N
construct
construct_braced1
construct_braced2
construct_variadic1
get
pack

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.

Description

adapted_to provides the way to access underlying "base" Function Object or Little Function from adapted Function Object.

Header
  • <boost/egg/adapted_to.hpp>
Notation
  • b is a "base" object such that __decltype(b) is B const &.
Valid expressions

Valid expression

Semantics

X_adapted_to<B>

A Major Function Object type

X_adapted_to<B>()(f)

Extracts b from f.

egg::adapted_to<B>(f)

X_adapted_to<B>()(f)

Preconditions
Example

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) );
}

See also
Description

always returns a Function Object always returning the same object.

Header
  • <boost/egg/always.hpp>
Model of
Notation
Valid expressions

Valid expression

Semantics

always(x)

A Major Function Object which holds bound(x).

always(x)(a1,...,aN)

__fwd_arg_list(bound(x), by_cref)

always_ref

Static Function Object

always_ref(y)

A Major Function Object

always_ref(y)(a1,...,aN)

__fwd_arg_list([y], by_perfect)

Preconditions
Example

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 );
}

See also
Description

identity returns argument unchanged.

Header
  • <boost/egg/identity.hpp>
Model of
Valid expressions

Valid expression

Semantics

X_identity<__Stg = __ud>

A Major Function Object type

X_identity<__Stg>()(a1)

__fwd_arg_list([a1], __Stg)

identity

X_identity<>()

Example

void egg_example()
{
    BOOST_CHECK( identity(10) == 10 );
}

See also
Description

apply calls a function with trailing arguments.

Header
  • <boost/egg/apply.hpp>
Model of
Valid expressions

Valid expression

Semantics

X_apply<__Stg = __ud>

A Major Function Object type

X_apply<__Stg>()(__pfo,a1,...,aN)

__const(__pfo)(__fwd_arg_list(a, __Stg))

apply

X_apply<>()

Preconditions
Example

void egg_example()
{
    std::negate<int> my_negate;
    BOOST_CHECK(
        apply(my_negate, apply(my_negate, apply(my_negate, 10))) == -10 );
}

Description

bll_N is a Lexically Typed Object which represents boost::lambda::_N.

[Caution] Caution

bll_N is neither statically initialized, Default Constructible nor Copy Assignable.

Header
  • <boost/egg/bll/placeholders.hpp>
Model of
Valid expressions

Valid expression

Semantics

bll_%%N

Polymorphic boost::lambda::_%%N

Invariants
  • 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.
Example

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 );
}

See also
Description

X_construct is constructor as Function Object.

Header
  • <boost/egg/construct.hpp>
Valid expressions

Valid expression

Semantics

X_construct<T, __Stg = __ud>

A Major Function Object type

X_construct<T, __Stg>()(a1,...,aN)

T(__fwd_arg_list(a, __Stg))

X_construct<>

X_construct<__mpl::_1, __mpl::_2>

Example

void egg_example()
{
    BOOST_CHECK( apply(X_construct<int>(), 3) == 3 );
}

See also
Description

X_construct_braced1 constructs object using braced-initializer.

Header
  • <boost/egg/construct_braced1.hpp>
Valid expressions

Valid expression

Semantics

X_construct_braced1<T, __Stg = __ud>

A Major Function Object type

X_construct_braced1<T, __Stg>()(a1,...,aN)

T t = {__fwd_arg_list(a, __Stg)}; return t;

X_construct_braced1<>

X_construct_braced1<__mpl::_1, __mpl::_2>

See also
Description

X_construct_braced2 constructs object using braced-initializer.

Header
  • <boost/egg/construct_braced2.hpp>
Valid expressions

Valid expression

Semantics

X_construct_braced2<T, __Stg = __ud>

A Major Function Object type

X_construct_braced2<T, __Stg>()(a1,...,aN)

T t = {{__fwd_arg_list(a, __Stg)}}; return t;

X_construct_braced2<>

X_construct_braced2<__mpl::_1, __mpl::_2>

See also
Description

X_construct_variadic1 constructs variadic object using braced-initializer.

Header
  • <boost/egg/construct_variadic1.hpp>
Valid expressions

Valid expression

Semantics

X_construct_variadic1<T, __Stg = __ud>

A Major Function Object type

X_construct_variadic1<T, __Stg>()(a1,...,aN)

T t = BOOST_EGG_VARIADIC_L {__fwd_arg_list(a, __Stg)} BOOST_EGG_VARIADIC_R; return t;

X_construct_variadic1<>

X_construct_variadic1<__mpl::_1, __mpl::_2>

See also
Description

get returns the N-th element from the beginning of the Fusion Forward Sequence.

Header
  • <boost/egg/get.hpp>
Notation
  • fusion is boost::fusion.
Valid expressions

Valid expression

Semantics

X_get<N>

A Major Function Object type

X_get<N>()(t)

fusion::deref(fusion::advance<N>(fusion::begin(t)))

X_get_c<n>

X_get< __mpl::int_<n> >

egg::get<N>(t)

X_get<N>()(t)

egg::get_c<n>(t)

X_get_c<n>()(t)

Example

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));
}

See also
Description

pack makes boost::tuple<...> for argument forwarding.

Header
  • <boost/egg/pack.hpp>
Model of
Notation
Valid expressions

Valid expression

Semantics

X_pack<__Stg = __ud>

A Major Function Object type

X_pack<__Stg>()(a1,...,aN)

boost::tuple<dts_(__fwd_arg_list(a, __Stg))>(__fwd_arg_list(a, __Stg))

pack

X_pack<>()

Preconditions
Example

void egg_example()
{
    BOOST_CHECK(
        boost::get<1>(pack(1,'1',std::string("one"))) == '1' );
}

See also

PrevUpHomeNext