Description
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code? Yes - It will eliminate the security vulnerabilities that arise from defining the arguments incorrectly via the cpp1 syntax - the same things that are eliminated by using in, out, inout, copy, forward and move in regular cpp2 function definitions instead of using the cpp1 syntax.
Will your feature suggestion automate or eliminate X% of current C++ guidance literature? It will make it unnecessary to learn about std::function (or at least unnecessary to learn about the old syntax for function signature, if keeping std::function around is desirable for some reason)
Describe alternatives you've considered.
I've recently written a functional (i.e. a function that receives functions and possibly data, and returns a composition of those functions and data.)
The current syntax, as far as I'm aware, is quite confusing, as it is necessary to specify that the arguments as well as the return value as type e.g. std::function(return_val(arg1_type,arg2_type))
- which is inconsistent with the cpp2 syntax and is not intuitive - it makes it necessary to both know about std::function, as well as the (hopefully to be) deprecated cpp1 function signature syntax.
There are three alternatives I thought of, I'll give an example for a functional that receives two functions - the first receives and int and returns an int, the second receives an int and returns a string, and the functional returns a function that receives an int and applies the latter function to the former one, while forwarding the received int to the former one:
- Using function type the same way we define a function type in cpp2:
f: (g: (int)->int, h: (int)->std::string)->(int)->std::string =
:(v)->(int)->std::string = h$(g$(v));
- Using parenthesis to make it a bit easier to parse:
f: (g: ((int)->int), h: ((int)->std::string))->((int)->std::string) =
:(v)->((int)->std::string) = h$(g$(v));
or
f: (g: <(int)->int>, h: <(int)->std::string>)-><(int)->std::string> =
:(v)-><(int)->std::string> = h$(g$(v));
- Using std::function, but with the cpp2 syntax:
f: (g: std::function<(int)->int>, h: std::function<(int)->std::string>)->std::function<(int)->std::string> =
return :(v)->std::function<(int)->std::string> = h$(g$(v));
The current syntax is quite confusing for people who aren't familiar with cpp1, and would unnecessarily require them to learn the old syntax along with the new:
f: (g: std::function<int(int)>, h: std::function<std::string(int)>->std::function<std::string(int)> =
return :(v)->std::function<std::string(int)> = h$(g$(v));
This is even more necessary if you consider the benefits of having in, out, inout, copy, forward and move defined for us in the function definitions that we receive and return (left out as default in
for brevity in the above examples) - which is one of the main motivators for cpp2 in the first place.