Reputation: 1785
In C++14 something like this was made legal (for lambdas
) :-
auto l = [](auto x, auto y) { return x+y; };
However something like this is still not legal :-
auto sum (auto x, auto y)
{
return x+y;
}
My curiosity is why wasn't the second one added to the standard (though it is supposed to be added in C++17 hopefully) ? What were the pros & cons of the second one ?
Upvotes: 5
Views: 253
Reputation: 11968
It's part of a TS that wasn't ready in time for C++14.
It is going to be equivalent to
template <typename T, typename U>
auto sum(T x, U y) { return x+y }
The only pro is that it's slightly shorter. Everything else is the same.
Upvotes: 3
Reputation: 385405
It wasn't added because it's another thing to add and time is not infinite. We cannot expect all useful enhancements to be added in one go, can we? As you have identified, it will be in C++17.
Upvotes: 6