Auto as function argument

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 not the second one added to the standard (although it is assumed that it will be added in C ++ 17, I hope)? What were the pros and cons of the second?

+5
source share
2 answers

It was not added, because one more addition and time are not infinite. We cannot expect all the useful improvements to be added at a time, right? As you have defined, this will be in C ++ 17.

+6
source

This is the part of TS that was not ready on time for C ++ 14.

It will be equivalent

 template <typename T, typename U> auto sum(T x, U y) { return x+y } 

The only professional is that he is a little shorter. Everything else is the same.

+3
source

Source: https://habr.com/ru/post/1239794/


All Articles