Live data from Hacker News

The Evolutions of Lambdas in C++14, C++17 and C++20

fluentcpp.com

1–10 of 75 posts

Re: The Evolutions of Lambdas in C++14, C++17 and C++20

#3
post #2

C++23 drop the word auto? myLambda = [](&&x){ std::cout what's the point of having to write auto everywhere

syntactical disambiguation, there's already something called "the most vexing parse". C++ is full of little holes like these and getting rid of auto would surely at least double compile times or at worst make parsing C++ actually impossible.

Re: The Evolutions of Lambdas in C++14, C++17 and C++20

#5
post #2

C++23 drop the word auto? myLambda = [](&&x){ std::cout what's the point of having to write auto everywhere

As seen from Python vs Lua: without a keyword for introduction it's less clear which scope a variable belongs to. Scopes are part of deterministic destruction in C++ and should not be taken lightly.

As a general preference, I'd always want a keyword to introduce a new variable, and most languages seem to agree even if they didn't have to.

Re: The Evolutions of Lambdas in C++14, C++17 and C++20

#6
Template lambdas is in my opinion the most useful evolution and has been a long time coming. I figure it was held back by template haters who want terse syntax and don't understand how it's much more powerful than auto/concepts.

I wouldn't say it's a smaller evolution than previous iterations.

Re: The Evolutions of Lambdas in C++14, C++17 and C++20

#7
post #2

C++23 drop the word auto? myLambda = [](&&x){ std::cout what's the point of having to write auto everywhere

syntactical disambiguation, there's already something called "the most vexing parse". C++ is full of little holes like these and getting rid of auto would surely at least double compile times or at worst make parsing C++ actually impossible.

That is what happens when a language makes the compromise to be copy-paste compatible with https://cdecl.org/

Re: The Evolutions of Lambdas in C++14, C++17 and C++20

#8
post #5
post #2

C++23 drop the word auto? myLambda = [](&&x){ std::cout what's the point of having to write auto everywhere

As seen from Python vs Lua: without a keyword for introduction it's less clear which scope a variable belongs to. Scopes are part of deterministic destruction in C++ and should not be taken lightly. As a general preference, I'd always want a keyword to introduce a new variable, and most languages seem to agree even if they didn't have to.

In this case x must obviously be in a new scope as all function parameters. There isn't possibly be an ambiguity here.

Re: The Evolutions of Lambdas in C++14, C++17 and C++20

#10
post #5

Earlier quoted context omitted.

As seen from Python vs Lua: without a keyword for introduction it's less clear which scope a variable belongs to. Scopes are part of deterministic destruction in C++ and should not be taken lightly. As a general preference, I'd always want a keyword to introduce a new variable, and most languages seem to agree even if they didn't have to.

In this case x must obviously be in a new scope as all function parameters. There isn't possibly be an ambiguity here.

I think grandparent is referring to myLambda - that could be a new variable or overwriting of an existing one.

I agree with them, in Python the number of times something like this happens:

    myVariable = 10
    myVariablr = clever_function(myVariable)
(note the typo in variable name)
Post reply on HN