3 ms·
About no. 4: That often translates into noticing C++ has gotten `auto` in C++11 with a later improvement in C++14: auto x { get_something_complicated() }; o
by einpoklum 4y ago
About no. 4: That often translates into noticing C++ has gotten `auto` in C++11 with a later improvement in C++14:
auto x { get_something_complicated() };
or
foo(int x) -> auto {
return get_something_complicated(bar(x));
}
so it's less "not-fun" these days.
- throwaway2037 4y agoI feel the same. Java and C# have an equivalent called 'var'. Unless the scope is tiny, I always avoid it. Also, in Java when you create a lambda, it is possible to exclude the parameter types. foo(x) -> get_something_complicated(bar(x)) It is not good for readability in large source bases.
- einpoklum 4y agoWith C++ lambdas, it's similar, but the syntax is a bit uglier: [](auto&& x) { return get_something_complicated(bar(x)); } and you can decide whether you want a value (no &'s), an lvalue reference (&), or a forwarding reference (&&). I think with C++20 you can also use a concept instead of auto for a constrained parameter type.