Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-03-08 05:13:44


Gabriel Dos Reis <gdr_at_[hidden]> writes:

> In -a- model I discussed a while ago with the second author of
> decltype/auto proposal, lambdas are unnamed constants that can be
> implemented by local classes. The body of the lambda would be
> forwarded-to by the appropriate overload of the call operator,
> i.e. your example would be
>
> foo: () -> auto {
> int i;
>
> struct xxx {
> operator(): (int x) -> auto { return i + x; }
> };
> };

Is foo missing a return statement?

> That is a very simple model that just provides a syntactic sugar
> (modulo use of auto in return type) for what you can do in current
> C++. In particular, it is clear that the reference to "i" is a hard
> error by application of current rules governing local classes.
>
> I do not believe in local variables that silently escape their lexical
> scopes. If you really want your automatic variables to espace, you
> already have ways to say so; but I don't think they should be the
> common cases that should be "optimized for".
>
>
> Note that I want the lambdas to be constants, in particular I would
> like to be able to use them as template arguments. Note also the type
> inference that can refer to local classes :-)

Sounds lovely ;-)

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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