|
Boost Users : |
From: Arnaldur Gylfason (arnaldur.gylfason_at_[hidden])
Date: 2006-10-19 07:23:44
>The upcoming version of Boost, 1.34, will contain the Boost.Typeof
library
>that will provide the BOOST_TYPEOF and BOOST_AUTO macros to emulate this
>facilities. The current snapshot of 1.34 can be obtained from Boost CVS.
Thanks for the info! Look forward to look at this.
The following works on g++ 4.0.2:
typedef typeof(lambda::_1 + lambda::_2) T1;
T1 f = lambda::_1 + lambda::_2;
typedef typeof(f*lambda::_1) T2;
T2 g = f*lambda::_1;
Let's say I have to parse "(_1 + _2)*_1" and "(_1/_2)*_1". I only get
these command strings at runtime so I don't know the expressions at
compile time.
I have to parse the strings and gradually build the lambda expression.
First the expression within parenthesis has to be created and then the
result combined with *_1
to create the final expression. The type of the first expression is not
the same in the 2 cases so how do I store/refer to the first expression?
All possible templates must be evaluated at compile ime so I somehow must
limit the possibilities at compile time. Furthermore how can I select a
type based on a runtime parameter?
I must admit I have overstretched myself here so I am not sure if I'm
overlooking something or if this is impossible.
I had thought about expression templates but I wouldn't want to duplicate
what the lambda library is already doing. Anyway it seems to me I would
have the same problem as above about
type deduction from a runtime parameter.
All helpful remarks greatly appreciated.
cheers
Arnaldur
"Arkadiy Vertleyb" <vertleyb_at_[hidden]>
Sent by: boost-users-bounces_at_[hidden]
18.10.2006 19:36
Please respond to
boost-users_at_[hidden]
To
boost-users_at_[hidden]
cc
Subject
Re: [Boost-users] creating lambda expressions incrementally
"Arnaldur Gylfason" <arnaldur.gylfason_at_[hidden]> wrote
>I´m writing a simple expression parser in boost::spirit that can parse a
>string like "_1 + _2" or "log(_1)" and return a function object that does
>just that.
>I used boost::lamda for that and return it as boost::function object.
>Now I want to parse compositions like "sqrt(_1*_1 + _2*_2)" or "(_1 +
>_2)*_2" etc. It is easy to parse this of course but I have to create the
>corresponding function incrementally (in a loop or recursively)
>and that means I have to keep incremental lambdas until the whole
>expression has been created.
>I can not store them as boost::function since they do not work with
lambda
>operator overloading (apart from the fact that it would be too costly).
>I need a lambda type for these intermediate lambda objects. I guess the
>auto type specifier would solve this but when will that be available I
>wonder?
The upcoming version of Boost, 1.34, will contain the Boost.Typeof library
that will provide the BOOST_TYPEOF and BOOST_AUTO macros to emulate this
facilities. The current snapshot of 1.34 can be obtained from Boost CVS.
>The typeof seems to provide a solution though. I was just trying it and
it
>seems to work!
For the Boost.Typeof library to handle lambda expressions, on the
platforms
where typeof is not natively supported, Boost.Lambda templates need to be
registered. The Boost.Typeof documentation describes this using
Boost.Lambda as an example. Generally it's up to maintainers of Lambda
library to decide if to provide the typeof support, and, to the best of my
knowledge, it won't happen in 1.34 :(
This registration of the lambda templates can be also done externally
(again, see the typeof docs on how to do this), but this has to be kept
in-sync with the Lambda templates.
The two Boost libraries to support typeof in 1.34 will be spirit and
xpressive.
Regards,
Arkadiy
_______________________________________________
Boost-users mailing list
Boost-users_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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