Boost C++ Libraries

PrevUpHomeNext

Function Adaptors

ambiN
compose
curryN
uncurry
fix
fuse
unfuse
indirect
lazy
memoize
mono
nestN
perfect
pipable
regular
return_
tagged

A Function Adaptor is a higher-order function that takes a "base" Function Object and returns an "adapted" Function Object. A Function Adaptor provides, if possible, two interfaces: A normal higher-order Function Object, and an MPL Metafunction with a 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 POD and the expression passed to the macro is a constant expression. Also, Function Adaptors don't modify Default Constructible and Copy Assignable-ness of base Function Object unless otherwise specified.

[Important] Important

If a macro argument is not guaranteed to contain no commas and recursions, you must use BOOST_EGG_XXX_L ... BOOST_EGG_XXX_R instead of BOOST_EGG_XXX(...).

Description

The ambi family helps you to make Ambi Function Object.

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

Valid expression

Semantics

result_of_ambi%%N<__PFo, __Bytag = __ud>::type

An Ambi Major Function Object type

BOOST_EGG_AMBI_L init BOOST_EGG_AMBI_R

A braced initializer of result_of_ambi%%N<__PFo,...>::type

BOOST_EGG_AMBI(I)

BOOST_EGG_AMBI_L I BOOST_EGG_AMBI_R

o|fc(d, __Bytag)(a1,...,aN)

__const(d)(__fwd_arg_list([o]++a, __Bytag))

X_ambi%%N<__Bytag = __ud>

A Major Function Object type

X_ambi%%N<__Bytag>()(d)

fc(d, __Bytag)

ambi%%N

X_ambi%%N<>()

Preconditions
Invariants
  • result_of_ambi%%N<__PFo,...>::type is POD if and only if __PFo is POD.
Example

struct base_my_plus
{
    typedef int result_type;

    int operator()(int x, int y) const
    {
        return x + y;
    }
};

result_of_ambi1<base_my_plus>::type const my_plus = BOOST_EGG_AMBI({}); 1

void egg_example()
{
    BOOST_CHECK( my_plus(1, 2) == 3 );
    BOOST_CHECK( ( 1|my_plus(2) ) == 3 );

    std::plus<int> std_plus;
    BOOST_CHECK( ambi1(std_plus)(1, 2) == 3 );
    BOOST_CHECK( ( 1|ambi1(std_plus)(2) ) == 3 );
}

1

Notice this is not ambi2 but ambi1.

See also
Description

compose is a Function Adaptor for function composition.

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

Valid expression

Semantics

result_of_compose<__PFo1, __PFo2, R0 = __ud, __Stg = __ud>::type

A Major Function Object type

BOOST_EGG_COMPOSE_L init1 , init2 BOOST_EGG_COMPOSE_R

A braced initializer of result_of_compose<__PFo1, __PFo2,...>::type

BOOST_EGG_COMPOSE(I1, I2)

BOOST_EGG_COMPOSE_L I1 , I2 BOOST_EGG_COMPOSE_R

fc(d1, d2, R0, Stg)(a1,...,aN)

__const(d1)(__const(d2)(__fwd_arg_list(a, __Stg)))

X_compose<R0 = __ud, __Stg = __ud>

A Major Function Object type

X_compose<R0, __Stg>()(d1, d2)

fc(d1, d2, R0, __Stg)

compose

X_compose<>()

Preconditions
  • 0 <= N && N <= __MAX_PACK_ARITY.
  • __PFo1 d1 = init1; is a valid expression.
  • __PFo2 d2 = init2; is a valid expression.
  • __decltype_r0(R0, d1(d2())) is a valid expression which specifies the nullary return type.
[Important] Important

The last precondition means that fc(d1, d2, R0, __Stg) is NOT nullary-callable if R0 is __ud.

Invariants
Example

int increment(int i)
{
    return i + 1;
}

int decrement(int i)
{
    return i - 1;
}

void egg_example()
{
    using namespace infix;
    int r = (&increment ^compose^ &decrement ^compose^ &increment)(3);
    BOOST_CHECK( r == 4 );
}

See also
Description

The curry family turn Function Objects into curried ones.

Header
  • <boost/egg/curry.hpp>
Model of
Notation
  • fc(d) is an object of result_of_curry%%N<__typeof(d)>::type initialized by d.
Valid expressions

Valid expression

Semantics

result_of_curry%%N<__PFo>::type

A Major Function Object type

BOOST_EGG_CURRY%%N%%_L init BOOST_EGG_CURRY%%N%%_R

A braced initializer of result_of_curry%%N<__PFo>::type

BOOST_EGG_CURRY%%N(I)

BOOST_EGG_CURRY%%N%%_L I BOOST_EGG_CURRY%%N%%_R

fc(d)(a1)...(aN)

__const(d)(__fwd_arg_list([a1,...,a(N-1)], by_value)++__fwd_arg_list([aN], by_perfect))

curry%%N(d)

fc(d)

Preconditions
  • N is the arity of __PFo such that 2 <= N && N <= BOOST_EGG_MAX_ARITY.
  • __PFo d = init; is a valid expression.
  • For all I such that 1 <= I && I <= N-1, __typeof(aI) is Copy Constructible.
Invariants
  • result_of_curry%%N<__PFo>::type is POD if and only if __PFo is POD.
[Note] Note

Arguments except for the last one are captured by-copy. When you need to capture by-reference, pass arguments using boost::ref.

Example

struct base_my_minus
{
    typedef int result_type;

    int operator()(int x, int y) const
    {
        return x - y;
    }
};

result_of_curry2<base_my_minus>::type const curried_minus = BOOST_EGG_CURRY2({});

void egg_example()
{
    BOOST_CHECK( curried_minus(4)(9) == -5 );
    BOOST_CHECK( curry2(base_my_minus())(4)(9) == -5 );
}

See also
Description

uncurry reverses curry.

Header
  • <boost/egg/uncurry.hpp>
Model of
Notation
  • fc(d, __Stg) is an object of result_of_uncurry<__typeof(d), __Stg>::type initialized by d.
  • parens(b1,...,bN) is (b1)(b2)...(bN).
Valid expressions

Valid expression

Semantics

result_of_uncurry<__PFo, __Stg = __ud>::type

A Major Function Object type

BOOST_EGG_UNCURRY_L init BOOST_EGG_UNCURRY_R

A braced initializer of result_of_uncurry<__PFo>::type

BOOST_EGG_UNCURRY(I)

BOOST_EGG_UNCURRY_L I BOOST_EGG_UNCURRY_R

fc(d, __Stg)(a1,...,aN)

__const(d)(parens(__fwd_arg_list(a, __Stg)))

X_uncurry<__Stg = __ud>

A Major Function Object type

X_uncurry<__Stg>()(d)

fc(d, __Stg)

uncurry

X_uncurry<>()

Preconditions
  • 2 <= N && N <= BOOST_EGG_MAX_ARITY.
  • __PFo d = init; is a valid expression.
Invariants
  • result_of_uncurry<__PFo,...>::type is POD if and only if __PFo is POD.
Example

void egg_example()
{
    std::plus<int> std_plus;
    BOOST_CHECK( uncurry(curry2(std_plus))(4, 9) == 13 );
}

See also
Description

fix is Fixed point combinator, which enables you to write recursive functions on the fly.

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

Valid expression

Semantics

fix(__pfo)(a1)

__const(__pfo)(fix(__pfo))(__fwd_arg_list([a1], by_perfect))

fix2

Static compose(fix, curry2)

[Note] Note

fix(__pfo) that is passed to __pfo as the first argument represents __pfo itself. Also notice that __pfo must be curried in advance.

Example

void egg_example()
{
    using bll::_1;
    using bll::_2;

    int r =
        fix2(
            bll::ret<int>(
                // \(f,a) -> a == 0 ? 1 : a * f(a-1)
                bll::if_then_else_return( _2 == 0,
                    1,
                    _2 * lazy(_1)(_2 - 1)
                )
            )
        ) (5);

    BOOST_CHECK(r == 5*4*3*2*1);
}

See also
Description

fuse converts a Function Object into a unary Function Object which takes a Fusion Forward Sequence.

Header
  • <boost/egg/fuse.hpp>
Model of
Notation
  • fc(d) is an object of result_of_fuse<__typeof(d)>::type initialized by d.
  • t_ is __fwd_arg_list(t, by_perfect).
Valid expressions

Valid expression

Semantics

result_of_fuse<__PFo>::type

A Major Function Object type

BOOST_EGG_FUSE_L init BOOST_EGG_FUSE_R

A braced initializer of result_of_fuse<__PFo>::type

BOOST_EGG_FUSE(I)

BOOST_EGG_FUSE_L I BOOST_EGG_FUSE_R

fc(d)(t)

__const(d)(egg::get_c<0>(t_),...,egg::get_c<N-1>(t_))

fuse(d)

fc(d)

Preconditions
Invariants
  • result_of_fuse<__PFo>::type is POD if and only if __PFo is POD.
Example

int unfused_plus(int i, int j, int k)
{
    return i + j + k;
}

void egg_example()
{
    BOOST_CHECK( 1+2+3 == fuse(&unfused_plus)(boost::make_tuple(1,2,3)) );
}

See also
Description

unfuse reverses fuse.

Header
  • <boost/egg/unfuse.hpp>
Model of
Notation
  • fc(d, R0, __Stg) is an object of result_of_unfuse<__typeof(d), R0, Pack, __Stg>::type initialized by d.
  • pack_ is X_pack<__Stg>() if Pack is __ud, __mpl::apply<Pack, __Stg>::type() otherwise.
Valid expressions

Valid expression

Semantics

result_of_unfuse<__PFo, R0 = __ud, Pack = __ud, __Stg = __ud>::type

A Major Function Object type

BOOST_EGG_UNFUSE_L init BOOST_EGG_UNFUSE_R

A braced initializer of result_of_unfuse<__PFo,...>::type

BOOST_EGG_UNFUSE(I)

BOOST_EGG_UNFUSE_L I BOOST_EGG_UNFUSE_R

fc(d, R0, __Stg)(a1,...,aN)

__const(d)( pack_(__fwd_arg_list(a, __Stg)) )

X_unfuse<R0 = __ud, Pack = __ud, __Stg = __ud>

A Major Function Object type

X_unfuse<R0, Pack, __Stg>()(d)

fc(d, R0, __ud)

unfuse

X_unfuse<>()

Preconditions
  • __PFo d = init; is a valid expression.
  • __decltype_r0(R0, d(pack_()) is a valid expression which specifies the nullary return type.
  • If Pack isn't __ud, __mpl::apply<Pack, by_ref>::type is a valid expression.
Invariants
  • result_of_unfuse<__PFo,...>::type is POD if and only if __PFo is POD.
Example

struct fused_print
{
    typedef void result_type;

    template<class Args>
    void operator()(Args const &args) const
    {
        boost::fusion::for_each(args, std::cout << bll::_1);
    }
};

result_of_unfuse<fused_print>::type const print = BOOST_EGG_UNFUSE({});

void egg_example()
{
    print(1, '2', "34");
}

See also
Description

indirect takes a pointer-like object then calls it after dereferencing.

Header
  • <boost/egg/indirect.hpp>
Model of
Notation
  • fc(p, __Stg) is an object of result_of_indirect<__typeof(p), __Stg>::type initialized by p.
Valid expressions

Valid expression

Semantics

result_of_indirect<Pco, __Stg = __ud>::type

A Major Function Object type

BOOST_EGG_INDIRECT_L init BOOST_EGG_INDIRECT_R

A braced initializer of result_of_indirect<Pco,...>::type

BOOST_EGG_INDIRECT(P)

BOOST_EGG_INDIRECT_L P BOOST_EGG_INDIRECT_R

fc(p, __Stg)(a1,...,aN)

(*p)(__fwd_arg_list(a, __Stg))

X_indirect<__Stg = __ud>

A Major Function Object type

X_indirect<__Stg>()(p)

fc(p, __Stg)

indirect

X_indirect<>()

Preconditions
Invariants
  • result_of_indirect<Pco,...>::type is POD if and only if Pco is POD.
Example

typedef
    result_of_pipable< 1
        result_of_indirect<T_pipable const *>::type
    >::type
T_pipi;

T_pipi const pipi 2
  = BOOST_EGG_PIPABLE_L
        BOOST_EGG_INDIRECT(&pipable) 3
    BOOST_EGG_PIPABLE_R;

struct counter :
    private boost::noncopyable
{
    typedef void result_type;

    template<class T>
    void operator()(T const &)
    {
        m_count += 1;
    }

    int m_count;
    counter() : m_count(0) {}
};

void egg_example()
{
    std::plus<int> plus;
    BOOST_CHECK( (1|pipable(plus)(3)) == 1+3 );
    BOOST_CHECK( (1|(plus|pipi)(3)) == 1+3 );

    counter c;
    int a[] = {1,2,3};
    std::for_each(a, a+3, indirect(&c)); 4
    BOOST_CHECK(c.m_count == 3);
}

1

Make pipable be Pipable Function Object.

2

&pipable is an address constant expression, so that pipi can be statically initialized.

3

A macro invocation must be sandwiched using _L and _R.

4

indirect(&c) is copyable, whereas c is not.

See also
Description

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.

Header
  • <boost/egg/lazy.hpp>
Model of
Notation
  • fc(f) is an object of result_of_lazy<__typeof(f), Bind>::type initialized by f.
  • bind_ is boost::lambda::bind if Bind is __ud, Bind() otherwise.
Valid expressions

Valid expression

Semantics

result_of_lazy<F, Bind = __ud>::type

A Major Function Object type

BOOST_EGG_LAZY_L init BOOST_EGG_LAZY_R

A braced initializer of result_of_lazy<F>::type

BOOST_EGG_LAZY(I)

BOOST_EGG_LAZY_L I BOOST_EGG_LAZY_R

fc(f)(a1,...,aN)

Polymorphic bind_(__fwd_arg_list([f]++a, by_value))

X_lazy<Bind = __ud>

A Major Function Object type

X_lazy<Bind>()(f)

fc(f)

lazy

X_lazy<>()

Preconditions
  • F f = init; is a valid expression.
Invariants
  • result_of_lazy<F, Bind>::type is POD if and only if F is POD.
[Tip] Tip

When you provide a lazy Function Object, its "base" function also should be provided with a consistent naming convention, so that your clients can use it with nestN.

Example

struct base_my_plus
{
    typedef int result_type;

    int operator()(int x, int y) const
    {
        return x + y;
    }
};

result_of_lazy<base_my_plus>::type const my_Plus = BOOST_EGG_LAZY({});

void egg_example()
{
    using bll::_1;
    using bll::_2;

    BOOST_CHECK( my_Plus(_1, 3)(bll::make_const(2)) == 5 ); 1

    int two = 2, four = 4;
    BOOST_CHECK( my_Plus(my_Plus(_1, 3), my_Plus(_2, _1))
        (two, four) == (2+3)+(4+2) );
}

1

Boost1.35 or later won't require make_const.

See also
Description

memoize stores the result of function for later reuse.

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

Valid expression

Semantics

memoize(__pfo)

A Major Function Object

memoize(__pfo)(a1)

__fwd_arg_list([__const(__pfo)(fixed, __fwd_arg_list([a1], by_value))], by_value)

Preconditions
Example

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 egg_example()
{
    BOOST_CHECK( fib(30) == 1346269 );
    BOOST_CHECK( memoize(fib)(30) == 1346269 );
}

See also
Description

mono turns a Function Object into a "monomorphic" one which contains no templates.

Header
  • <boost/egg/mono.hpp>
Notation
  • fc(f) is an object of result_of_mono<__typeof(f), Sig>::type initialized by f.
  • 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.
  • bI is boost::implicit_cast<ParamOf(Sig, I)>(aI).
Valid expressions

Valid expression

Semantics

result_of_mono<Fun, Sig>::type

A Major Function Object type

BOOST_EGG_MONO_L init BOOST_EGG_MONO_R

A braced initializer of result_of_mono<Fun,...>::type

BOOST_EGG_MONO(I)

BOOST_EGG_MONO_L I BOOST_EGG_MONO_R

fc(f)(a1,...,aN)

__const(f)(b1,...,bN)

X_mono<Sig>

A Major Function Object type

X_mono<Sig>()(f)

fc(f)

egg::mono<Sig>(f)

X_mono<Sig>()(f)

Preconditions
Invariants
  • result_of_mono<Fun,...>::type is POD if and only if Fun is POD.
  • result_of_mono<Fun,...>::type is Adaptable if and only if N is 1 or 2.
Example

void egg_example()
{
    BOOST_CHECK(
        std::not1(
            egg::mono<bool(int const&)>(bll::_1 != 12)
        ) (12)
    );

    BOOST_CHECK(
        std::bind1st(
            egg::mono<boost::use_default(int const&, int const&)>(bll::_1 == bll::_2),
            12
        ) (12)
    );
}

See also
Description

nestN is generalization of curryN and lazy, which enables you to write nested lambda expressions. N represents nesting level of lambda expression.

Header
  • <boost/egg/nest.hpp>
Model of
Notation
  • bll_bind is an imaginary Function Object behaving as if it were boost::lambda::bind.
  • wrap_ref_ is an imaginary Function Object behaving as if it were boost::ref.
  • unwrap_ref_ is an imaginary Function Object which extracts a wrapped reference from boost::reference_wrapper.
  • bind_ is bll_bind if Bind is __ud, Bind() otherwise.
  • protect_ is boost::lambda::protect if Protect is __ud, Protect() otherwise.
  • LAZY(N) is:
    • If N == 0, X_identity<by_value>().
    • Else if N == 1, X_lazy<__typeof(bind_)>().
    • Otherwise, X_lazy<result_of_lazy<__typeof(bind_), result_of_lazy<__typeof(bind_),...N-1 times...>::type>::type>().
Valid expressions

Valid expression

Semantics

X_nest%%N<Bind = __ud>

A Major Function Object type

X_nest%%N<Bind>()(f)(a1,...,aK)

Polymorphic LAZY(N)(f)(__fwd_arg_list(a, by_value))

nest%%N(x)

X_nest%%N<>()(x)

X_ref%%N<Bind = __ud>

A Major Function Object type

X_ref%%N<Bind>()

Polymorphic compose(X_nest%%N<Bind>()(unwrap_ref_), wrap_ref_)

ref%%N

Static X_ref%%N<>()

XX_%%M%%_<Protect = __ud>

A Major Function Object type

XX_%%M%%_<Protect>()(p)

Polymorphic protect_(protect_(...M times...(p)...))

_%%M%%_

Static XX_%%M%%_<>()

using BOOST_EGG_NEST_NAMES;

using-declarations of nest%%N, ref%%N, _%%M%%_, and boost::lambda::_%%K.

Preconditions
  • 0 <= N && N <= BOOST_EGG_MAX_ARITY.
  • 0 <= M && M <= N-1.
[Important] Important

For capturing by-reference in nested lambda expressions, refN must be used instead of boost::ref.

Example

int & second(int, int &j, int, int)
{
    return j;
}

void egg_example()
{
    using bll::_1;
    using bll::_2;
    std::plus<int> plus;
    std::minus<int> minus;

    int i6 = 6, i1 = 1, i3 = 3, i9 = 9;

// Lv: 0     1      2          3
    // \x -> (\y -> (\(z,w) -> foo(y,w,z,x))))
    BOOST_CHECK( nest3(foo)(_1_(_1), _2_(_2), _2_(_1), _0_(_1)) 1
        (i3)(i6)(i1,i9) == foo(6,9,1,3) );

    // \x -> apply(\y -> minus(x,y), plus(x,3))
    BOOST_CHECK( nest1(apply)(nest2(minus)(_0_(_1), _1_(_1)), nest1(plus)(_0_(_1), 3)) 2
        (i9) == minus(9, plus(9,3))  );

    int w = 7;
    // \x -> (\y -> (\z -> second(y,w,z,x))))
    BOOST_CHECK(
        boost::addressof(
            nest3(second)(_1_(_1), ref3(w), _2_(_1), _0_(_1)) 3
                (i1)(i1)(i1)
        ) == boost::addressof(w) );
}

1

_M_ turns a placeholder into nested one.

2

By the definition, nest1 has the same semantics as lazy.

3

Captures w by-reference.

See also
Description

perfect performs "perfect forwarding".

Header
  • <boost/egg/perfect.hpp>
Model of
Notation
  • fc(d) is an object of result_of_perfect<__typeof(d)>::type initialized by d.
Valid expressions

Valid expression

Semantics

result_of_perfect<__PFo>::type

A Major Function Object type

BOOST_EGG_PERFECT_L init BOOST_EGG_PERFECT_R

A braced initializer of result_of_perfect<__PFo>::type

BOOST_EGG_PERFECT(I)

BOOST_EGG_PERFECT_L I BOOST_EGG_PERFECT_R

fc(d)(a1,...,aN)

__const(d)(__fwd_arg_list(a, by_perfect))

perfect(d)

fc(d)

Preconditions
  • __PFo d = init; is a valid expression.
Invariants
  • result_of_perfect<__PFo>::type is POD if and only if __PFo is POD.
Example

struct imperfect
{
    template<class FunCall>
    struct result;

    template<class Fun, class A>
    struct result<Fun(A &)>
    {
        typedef A &type;
    };

    template<class A>
    A & operator()(A &a) const
    {
        return a;
    }
};

void egg_example()
{
    BOOST_CHECK( perfect(imperfect())(3) == 3 );
}

See also
Description

pipable adapts Function Object into Pipable Function Object.

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

Valid expression

Semantics

result_of_pipable<__PFo, __Stg = __ud, __Bytag = __ud>::type

A Pipable Major Function Object type

BOOST_EGG_PIPABLE_L init BOOST_EGG_PIPABLE_R

A braced initializer of result_of_pipable<__PFo,...>::type

BOOST_EGG_PIPABLE(I)

BOOST_EGG_PIPABLE_L I BOOST_EGG_PIPABLE_R

o|fc(d, __Stg, __Bytag)(a1,...,aN)

__const(d)(__fwd_arg_list([o], __Bytag)++_safe_arg_list(a, __Stg))

X_pipable<__Stg = __ud, __Bytag = __ud>

A Major Function Object type

X_pipable<__Stg, __Bytag>()(d)

fc(d, __Stg, __Bytag)

pipable

X_pipable<>()

Preconditions
Invariants
  • result_of_pipable<__PFo,...>::type is POD if and only if __PFo is POD.
[Tip] Tip

When you provide a Pipable Function Object, its "base" function also should be provided with a consistent naming convention, so that your clients can use it with result_of.

Example

struct weird_mult
{
    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<weird_mult>::type const mult = BOOST_EGG_PIPABLE({});

void egg_example()
{
    BOOST_CHECK( ( 2|mult ) == 2 * 2 );
    BOOST_CHECK( ( 2|mult() ) == 2 * 2 );
    BOOST_CHECK( ( 2|mult(3)|mult(4) ) == 2 * 3 * 4 );
    BOOST_CHECK( ( 2|mult(3, 4) ) == 2 * 3 * 4 );

    BOOST_CHECK( ( mult|=2 ) == 2 * 2 );
    BOOST_CHECK( ( mult()|=2 ) == 2 * 2 );
    BOOST_CHECK( ( mult|=mult|=2) == (2 * 2) * (2 * 2) );

    BOOST_CHECK( ( mult(3)|=2 ) == 2 * 3 );
    BOOST_CHECK( ( mult(3, 4)|= 2 ) == 2 * 3 * 4 );
}

See also
Description

A Boost.Lambda Function Object is neither Default Constructible nor Copy Assignable. An iterator holding such a Function Object can't conform to even Input Iterator. regular converts it into comfortable one for iterators.

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

Valid expression

Semantics

regular(f)

A Major Function Object which is Default Constructible and Copy Assignable.

regular(f)(a1,...,aN)

__const(f)(__fwd_arg_list(a, by_perfect))

Preconditions
Example

void egg_example()
{
    int a1[6] = {1,2,3,4,5,6};
    int a2[3] = {2,4,6};

    BOOST_CHECK(
        std::equal(a2, a2+3,
            boost::make_filter_iterator(regular(bll::_1 % 2 == 0), a1, a1+6) )
    );
}

See also
Description

return_ just calls Function Object, possibly with a modified return type.

Header
  • <boost/egg/return.hpp>
Notation
  • fc(f, R, __Stg) is an object of result_of_return<__typeof(f), R, __Stg>::type initialized by f.
Valid expressions

Valid expression

Semantics

result_of_return<Fun, R = __ud, __Stg = __ud>::type

A Major Function Object type

BOOST_EGG_RETURN_L init BOOST_EGG_RETURN_R

A braced initializer of result_of_return<Fun,...>::type

BOOST_EGG_RETURN(I)

BOOST_EGG_RETURN_L I BOOST_EGG_RETURN_R

fc(f, R, __Stg)(a1,...,aN)

__const(f)(__fwd_arg_list(a, __Stg))

X_return<R, __Stg = __ud>

A Major Function Object type

X_return<R, __Stg>()(f)

fc(f, R, __Stg)

egg::return_<R>

X_return<R>()

Preconditions
Invariants
  • result_of_return<Fun,...>::type is POD if and only if Fun is POD.
Example

void egg_example()
{
    BOOST_CHECK( egg::return_<std::string>(bll::_1)("string").size() == 6 );
}

See also
Description

tagged makes a new distinct Function Object type. This emulates support for strong typedefs.

Header
  • <boost/egg/tagged.hpp>
Notation
  • fc(d, Tag, __Stg) is an object of result_of_tagged<__typeof(d), Tag, __Stg>::type initialized by d.
Valid expressions

Valid expression

Semantics

result_of_tagged<__PFo, Tag, __Stg = __ud>::type

A Major Function Object type

BOOST_EGG_TAGGED_L init BOOST_EGG_TAGGED_R

A braced initializer of result_of_tagged<__PFo,...>::type

BOOST_EGG_TAGGED(I)

BOOST_EGG_TAGGED_L I BOOST_EGG_TAGGED_R

fc(d, Tag, __Stg)(a1,...,aN)

__const(d)(__fwd_arg_list(a, __Stg))

tag_of<F>::type

Tag if F is __typeof(fc(d, Tag, __Stg)), unspecified type otherwise.

is_tagged_with<F, Tag>

boost::is_same<tag_of<F>::type, Tag>

Preconditions
  • Tag is any (possibly incomplete) type.
  • __PFo d = init; is a valid expression.
Invariants
  • result_of_tagged<__PFo,...>::type is POD if and only if __PFo is POD.
  • result_of_tagged<__PFo, Tag1,...>::type is the same type as result_of_tagged<__PFo, Tag2,...>::type if and only if Tag1 is the same type as Tag2.
Example

struct tag1;
struct tag2;
typedef result_of_tagged<std::multiplies<int>, tag1>::type my_mult1;
typedef result_of_tagged<std::multiplies<int>, tag2>::type my_mult2;

void egg_example()
{
    BOOST_CHECK( my_mult1()(3, 5) == my_mult2()(3, 5) );
    BOOST_STATIC_ASSERT(( !boost::is_same<my_mult1, my_mult2>::value ));
    BOOST_STATIC_ASSERT(( is_tagged_with<my_mult1, tag1>::value ));
}

See also

PrevUpHomeNext