|
Boost : |
From: Arkadiy Vertleyb (vertleyb_at_[hidden])
Date: 2004-07-23 19:37:15
"Andy Little" <andy_at_[hidden]> wrote
> "Arkadiy Vertleyb" <vertleyb_at_[hidden]> wrote
> > "Andy Little" <andy_at_[hidden]> wrote
> >
> > > ...I think spirit and lambda already have their own type
> > > deduction schemes, making it easy to implement there.
> >
> > I am unaware of such schemes.
>
> I dont know about spirit but lambda has:
> template<>
> struct plain_return_type_2<
> boost::lambda::arithmetic_action<
> boost::lambda::plus_action
> >
> > {
> typedef ... type;
> };
>
> etc
> which is IMO a type deduction scheme.
I think (and please correct me if I am wrong) this allows to determine
return type rather than the type of the expression itself.
Take the following Lambda functor:
_1 > 15 && _2 < 20
It's return type is "bool". The type of the functor itself is (please get
ready):
lambda_functor<
lambda_functor_base<
logical_action<and_action>,
tuple<
lambda_functor<
lambda_functor_base<
relational_action<greater_action>,
tuple<
lambda_functor<placeholder<1> >,
int const
>
>
>,
lambda_functor<
lambda_functor_base<
relational_action<less_action>,
tuple<
lambda_functor<placeholder<2> >,
int const
>
>
>
>
>
>
If you want to allocate a named object of this type (provided you don't want
to use Boost.Function, which imposes runtime penalties), you have to write
this in your code.
OTOH, With auto you would just write:
auto f = _1 > 15 && _2 < 20; // the compiler computes type for you
And with the library we are corrently discussing:
BOOST_AUTO(f, _1 > 15 && _2 < 20);
Which is not such a bad approximation, IMO.
> > What exactly is lacking?
>
> Nothing... Its perfect :-)
:-))
Regards,
Arkadiy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk