Does code like this:
auto add(auto a, auto b) { return a + b; }
violate the ISO c++14 standard? Will future versions of the standard allow code to be written like that?
[Does this] violate the ISO c++14 standard?
Yes, you can not declare functions taking parameters using auto
in C++14 (or C++17 for that matter). This code is ill-formed.
Will future versions of the standard allow code to be written like that?
The current Concepts TS does allow for this, it's usually referred to as terse function template syntax. In Concepts, the meaning is equivalent to:
template <class T, class U>
auto add(T a, U b) { return a + b; }
That part of the Concepts proposal also allows concept names to be used, not just auto
. It is an open question as to whether this will be part of a future C++ standard.
Update: The code will be valid in C++20, and have meaning equivalent to the function template I showed above (NB: a
and b
are deduced independently).