This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [lambda] Segmentation fault in simple lambda program


On 08/04/2009 09:35 AM, John Freeman wrote:

In my opinion, lambdas are not intended as just a shortcut to writing a
function object class. This is why our proposal did not require that
lambdas be implemented as classes; it is simply one implementation.
(Awaiting word to see if this is still the case in the working draft of
the standard; it may not be, but that doesn't change my opinion :)

From N2859: "The type of the lambda-expression (which is also the type of the closure object) is a unique, unnamed non-union class type—called the closure type...."


IMO, it's better to define new functionality in terms of already familiar features rather than have to specify everything about how a new feature interacts with the rest of the language.

Thus,
users should never see the class name. In warnings and errors, a lambda
should be treated like an anonymous class, swapping its
compiler-generated name with a placeholder like <lambda function>
(similar to <anonymous class>).

Yep.


Since templates work so differently from normal functions, I'm a little
uncomfortable with the idea of templates that don't involve any template
syntax, just the use of auto in the parameter list. But I'm open to
giving it a try, at least in the lambda context. Maybe outside of
lambda it could be used with a small template introducer...

In response to Jason's concern here, a template implementation is not required, just convenient. Hopefully you won't think of it as "templates without template syntax", but "deduction using the existing template mechanism".

As above, suggesting that it doesn't have to be a template suggests that there's a lot more specification left to do, such as how do you deal with expressions whose type you don't know yet? If you allow non-lambda uses, how do they fit into overload resolution? If you just say it's a template, we already know how they work.


Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]