Boost logo

Boost Users :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2005-02-02 06:19:56


Philippe Mori writes:
> I do not understand well the semantic of some constructs.
>
> 1) For t1,

Namely,

    typedef mpl::lambda<mpl::lambda<_1> >::type t1;

> does the external mpl::lambda has any effect on some
> use of t1

Yes. 'lambda' metafunction itself doesn't have a special status in,
well, lambda expressions, and the above doesn't behave any differently
from the following rewrite:

    template< typename T > struct f : lambda<T> {};

    typedef mpl::lambda< f<_1> >::type t1;

> or mpl::lambda<_1>::type and also mpl::lambda<_1>
> are always equivalent?

Since 'lambda' is a regular metafunction, 'lambda<_1>' and
'lambda<_1>::type' are not equivalent. The former is a nullary
metafunction, and the latter yields the result of the invocation,
which happens to be '_1'.

>
> 2) Does the uses of lambda in t8

Namely,
    
    typedef mpl::apply<_1,mpl::lambda< mpl::plus<_1,_2> > >::type t8;

> has any effect or the result is always the same as with t2.

't2', that is

    typedef mpl::apply<_1,mpl::plus<_1,_2> >::type t2;

is simply identical to 'mpl::plus<_1,_2>' (which you can verify using
BOOST_MPL_ASSERT). Likewise, 't8' is identical to
'mpl::lambda< mpl::plus<_1,_2> >'.

>
> 3) Does there are other tests that the ones below (i to vii) that
> would shows some other differences in the semantics of the
> expression?

Yep. Test cases in "$BOOST_ROOT/libs/mpl/test/apply.cpp"
(http://cvs.sourceforge.net/viewcvs.py/boost/boost/libs/mpl/test/apply.cpp?rev=1.5&view=markup)
assert many of the expressions appearing in the exercise + a few other
corner cases.

>
> 4) Same question but for to_be_filled part of my tests.
> Anything different that the four ones belows (a to d)?

Ignoring the fact that some combinations won't make much sense or
won't compile (e.g. 'display_type(mpl::apply<t3,to_be_filled>::type'),
'to_be_filled' part won't influence general behavior of any of these
constructs.

>
> 5) In any ot the tests with a to_be_filled part, is it
> possible to have more than one template argument
> and that the extra ones are used?

With some of t's, e.g. 't2', you'd _have_ to provide a second argument
for the 'apply' expression(s) to compile. In general, both lambda and
bind expressions allow for an arbitrary number of extra arguments (<=
BOOST_MPL_LIMIT_METAFUNCTION_ARITY, of course) which are discarded
(similarly to Boost.Bind).

>
> The thing I have some of the following (what I have tried and
> what compile depends on the construct - that is t1, t2,...) :
>
> i) display_type(tn);
>
> ii) display_type(tn::type);
> iii) display_value(tn::type::value);
>
> iv) display_type(mpl::apply<tn, to_be_filled>::type)
> v) display_value(mpl::apply<tn, to_be_filled>::type::value)
>
> vi) display_type(tn::apply<to_be_filled>::type)
> vii) display_value(tn::apply<to_be_filled>::type::value)
>
> where tn is one of the type t1, t2,... t8 and
> to_be_filled is something similar to one of those :
>
> a) int
> b) X where X is a metafunction class
> c) mpl::plus<int_<1>, int_<2> >
> d) Y where Y is a simple metafunction similar to always_int in
> section 3.5.4.
>
> I have look at the documentation but it is hard to see the relation
> between each construct, the possible uses of each ones and
> their prmary purpose. I would be nice to provide more samples
> and more equivalences.

Hope the above helps!

Sorry for the late reply,

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net