Boost logo

Boost :

Subject: Re: [boost] Rave for proposed Boost.Local (functions)
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-02-05 12:26:13


On Fri, Feb 4, 2011 at 5:03 PM, Alexander Nasonov <alnsn_at_[hidden]> wrote:
> Thomas Heller wrote:
>> Gregory Crosswhite wrote:
>> > To my mind this example looks a lot clearer if you reformat it as follows:
>> >
>> >          BOOST_LOCAL_FUNCTION(
>> >              (void) (add)(
>> >                  (double)(num)
>> >                  (const bind)((factor))
>> >                  (bind)((&sum))
>> >              )
>> >          ) {
>> >              sum += factor * num;
>> >              std::clog<<  "Summed: "<<  sum<<  std::endl;
>> >          } BOOST_LOCAL_FUNCTION_END(add)
>> >          add(100.0);
>>
>> As far is a am concerned, I still find this syntax overly verbose.
>> I do realize though that this is just a toy example. For better comparison,
>> Here is how the same thing would like in Boost.Phoenix:
>
> Steven and I were playing with different syntaxes few years ago
>
> We came up with something like this:
>
>    void BOOST_LOCAL_FUNCTION
>        ( BOOST_BIND((factor)(&sum)), double num )
>    {
>        sum += factor * num;
>        std::clog<<  "Summed: "<<  sum<<  std::endl;
>    }
>    BOOST_LOCAL_FUNCTION_DECL(add)
>
> http://thread.gmane.org/gmane.comp.lib.boost.devel/168612/focus=168694

Yes, Alex that is exactly where I started and I cannot thank you
enough for your Boost.ScopeExit work which has served as a solid basis
for my Boost.Local development.

However:
1) How is this syntax is preferable to Boost.Local parenthesized
syntax? To me, there is not much difference.*
2) How would you pass multiple local function parameters (not just the
one parameter `num`) using this syntax?
3) Can you generate local function that are passed as template
parameters using this syntax?

(*) I personally find the parenthesized syntax actually simpler
because it's -- more or less ;) -- like normal C++ syntax but with all
tokens wrapped within extra parenthesis.

Furthermore, the parenthesized syntax is more general than the above
macro syntax because it can be extended to specify concepts,
preconditions, postconditions, named parameters, etc. This might not
be so relevant for Boost.Local discussions but for example you can
re-write all Boost.Parameter (can Boost.ConceptCheck) macros to use
the same parenthesized syntax that Boost.Local uses. Therefore, the
API of all Boost libraries that spoil function declarations using
macros could be unified under the parenthesized syntax... if there
were an interest in doing so (as originally questioned by Andrzej
Krzemienski http://lists.boost.org/Archives/boost/2010/05/166098.php).

-- 
Lorenzo

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk