|
Boost : |
Subject: Re: [boost] [local_function] any interest in a LocalFunction library?
From: Pierre Morcello (pmorcell-cppfrance_at_[hidden])
Date: 2010-08-31 16:33:40
> > Sorry, I think I just realized I told you something
> wrong earlier on the list. One year ago, interest was raised
> towards unnamed local fonction. I missed that you were
> aiming for named function. we did not discuss named local
> function.
>
> Do you have a link to that email thread? I would like to
> take a closer
> look at that discussion.
>
the beginning discussion was there :
http://archives.free.net.ph/message/20090906.123719.b890ff7a.el.html
and the point that interest you can be seen there :
http://lists.boost.org/Archives/boost/2009/09/156126.php
>Lorenzo Caminiti wrote :
>Why is it necessary to wrap the code within the local function if the local function has no parameter and it is executed only once right after its definition?
In that proposition, they are parameters (but not return types, neither function name). It was proposed to be able to use 'early return' (see the discussion link), as a complement for a 'Breakable' macro.
Since the discussion was not clearly on local function, I had no clear interface, and I tested a lot of different looks/interfaces for the macro (like those you saw in my previous mail). I even tested named functions.
I think you did better than I did in the end (I did not find how to transmit 'this' as you did + your interface is good ), well done!
Still, unnamed void function with N parameters, that are called immediately are useful in certain cases (not always of course).
> One (the only?) reason I can think of for local functions
> with no parameters and single immediate execution is to implement
> constant-correct code blocks -- which were my original need
> for local
> functions in Boost.Contract. For example:
>
> void f(int x) {
> int y = x;
>
> const { // Const-block but doesn't work in
> C++ :(
> assert(y == x); // Within
> const-block so compiler error if I
> mistake this with `y = x`.
> }
>
> ...
> }
>
I find it a very good idea! No need for std::equal_to etc... will make some code ligther.
Thanks for your clear answers,
Best,
Pierre Morcello
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk