I can't understand why complex lambdas syntax were added into 'C++11' instead of just allowing local functions to be defined. In other words why this:
int main()
{
auto lambda = []() { };
}
And not this:
int main()
{
void lambda() { }
}
I can guess you'll point out that it's because local functions won't be usable in expressions but that wouldn't be exactly true as syntax supporting this form could be easily added very intuitively by just enabling temporary functions. Something like this:
int main()
{
void func(auto callable) ;
func( (void ()) { } ); //here we are basically creating a temporary of function type
}
Just to give a working example demonstrating that this is actually possible to be implemented I'll use GCC 'C' which support similar syntax by extension:
Life Example.
Aucun commentaire:
Enregistrer un commentaire