Boost logo

Boost :

Subject: Re: [boost] New libraries implementing C++11 features in C++03
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2011-11-24 11:44:22


On Thu, Nov 24, 2011 at 11:40 AM, Dean Michael Berris
<mikhailberis_at_[hidden]> wrote:
> On Fri, Nov 25, 2011 at 3:23 AM, Thomas Klimpel
> <Thomas.Klimpel_at_[hidden]> wrote:
>> Dean Michael Berris wrote:
>>>>> There's *exactly* the same number of lines in a local function as
>>>>> there is with a class/namespace function. What am I missing?
>>>>
>>>> I'm actually also asking myself what I'm missing. Everybody seems to
>>>> claim that a namespace function provides the same functionality as a
>>>> local function.
>>>
>>> [...]
>>> It's not that complicated.
>>>
>>> The first approach is the way we've been doing it with normal C++. It
>>> works. It's not broken.
>>>
>>> I don't see why we'd ever need Boost.Local at all.
>>
>> OK, now I understand what you are missing. An important part of the functionality of Boost.Local is to capture variables from the enclosing function. Some even argued that C++ will never have true local functions, because you still have to specify the names of the variables from the enclosing function that you want to capture.
>>
>
> int i;
> bool b;
> long l;
> auto local_function = [i, b, l](std::string const & s) {
>  // do what I want here.
> }
> // use local_function somewhere else
>
> Hmmm?
>
> Or better yet, works now:
>
> namespace foo {
>  void non_local_function(int i, bool b, long l, std::string const & s) {
>    // do what I want here.
>  }
>
>  void f(std::vector<double> const &v) {
>    int i;
>    bool b;
>    long l;
>    for_each(begin(v), end(v), bind(&non_local_function, i, b, l, _1));
>  }
> }
>
> See, no voodoo required here.
>
>> Of course, if you don't need to capture any variable from the enclosing function, using Boost.Local will only make your code more ugly.
>>
>
> I agree.
>
> Now, do I still miss anything?

Again, you are missing C++03 which will make your local_function
example above not compile (obviously) and which is the point of this
thread.

HTH,
--Lorenzo


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