|
Boost : |
Subject: Re: [boost] Rave for proposed Boost.Local (functions)
From: Joel de Guzman (joel_at_[hidden])
Date: 2011-02-03 08:15:35
On 2/3/2011 5:44 PM, Mathias Gaunard wrote:
> On 03/02/2011 01:19, Joel de Guzman wrote:
>> On 2/3/11 7:13 AM, Mathias Gaunard wrote:
>>> Doing anything non-trivial with Phoenix requires creating lazy functions
>>> beforehand (typically done at namespace scope).
>>> The fact that Phoenix itself bundles many lazy functions for any other
>>> container member and standard algorithm (for a total of 4,000 lines of
>>> code for that task alone) is testament to that; you can't really work
>>> with it otherwise.
>>
>> If you unwrap the macros from Boost.Local, something like a
>> Phoenix.function will emerge. So, why not just provide a phoenix
>> macro to give you the same level of verbosity and the same level
>> of debuggability and c++ syntax error handling?
>>
>> It is trivial to write such a macro in phoenix.
>
> Consider I want to write a function that does _1.foo(_2.bar()) + _3.baz.
>
> If I did as you suggested, I would end up writing three macro invocations before finally
> being able to write a readable phoenix expression.
>
> shortest syntax possible in C++03 -- return type could be avoided in C++0x -- (with Tn to
> be replaced by actual types):
>
> SHORT_FUNCTION(T2, foo, (T0 a, T1 b), a.foo(b))
> SHORT_FUNCTION(T1, bar, (T3 a), a.bar())
> SHORT_FUNCTION(T2, baz, (T4 a), a.baz)
>
> auto f = foo(_1, bar(_2)) + baz(3);
>
> I might as well write:
>
> SHORT_FUNCTION(T2, f, (T0 a, T3 b, T4 c), a.foo(b.bar()) + c.baz)
>
> Note I don't even have to specify T1 here.
>
> I could have written the expression as this though (not sure if I remember the right syntax):
>
> SHORT_FUNCTION(T2, foo, (T0 a, T1 b), a.foo(b))
> auto f = foo(_1, (_2->*&T2::bar)()) + (_3->*&T3::baz)();
>
> but not only is that verbose, I still need to define a foo lazy function because T0::foo
> could be overloaded (casting to select the right overload is even more horrible than the
> ->* syntax).
>
> Now, let's consider another case, I want to do a.foo(b.bar()) + c.baz, but with a, b, and
> c taken from the scope, and I don't want to have to specify the types of a, b, and c.
> I can't do that in Phoenix without defining the foo, bar and baz functions at namespace
> scope, since they must have a template operator(), which is only allowed at that level.
> I can, however, do that with no problem with Boost.Local.
Well, you have seen nothing yet ;-)
Regards,
-- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk