Boost logo

Boost :

Subject: Re: [boost] [local] Review
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-11-21 10:54:50


On Mon, Nov 21, 2011 at 10:44 AM, Hartmut Kaiser
<hartmut.kaiser_at_[hidden]> wrote:
>> > For everything else, there already exist a couple of solutions
>> (Boost.Bind, Boost.Lambda and Boost.Phoenix). I would like to see
>> improvements in ease of use in these libraries instead of advertising a
>> completely macro based solutions.
>>
>> In no way are Boost.Bind, Boost.Lamda, and Boost.Phoenix equivalent to
>> Boost.Local in functionality in practice.  In Boost.Local, you have to
>> learn some new (relatively straightforward) syntax for declaring the local
>> function, but the function body is plain C++.  For the other libraries by
>> contrast you have to learn a completely new syntax for writing *all* of
>> the code in your function, and if you get something wrong you get
>> literally pages of error messages that give you no insight as to what
>> happened.  The learning curve for Boost.Local is lightyears ahead of the
>> competitors.
>>
>> I personally don't like the verbosity of Boost.Local so I often prefer to
>> start by using Boost.Lambda instead for small functions instead, but I
>> can't tell you how many times I have eventually decided to give up and
>> just use Boost.Local because it was becoming a waste of my time to figure
>> out what the obscure error messages were telling me about what went wrong.
>
> Sorry, I still don't get it - so please excuse my ignorance.
>
> What exactly is missing from C++11 lambdas for them to be useful as local
> functions?
>
>    void foo()
>    {
>        auto f = [](){ cout << "Hey, I'm a local function!\n"; }
>        f();
>    }
>
> Why do we need Boost.Local instead?

As it was clarified in a couple of other reviews, if you have C++11
lambdas, you'd probably use them instead of Boost.Local (the only plus
of Boost.Local is that you don't need extra variables to bind by const
but that's a minor advantage). If instead you need to write local
functions that will work on both C++03 and C++11, you can use
Boost.Local and on C++11 the local functions programmed with
Boost.Local will have the same performance as lambdas.

--Lorenzo


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