Can I legally use names for template parameters in std::function
(or another similar construct)? E.g. given the code
std::function<int(int, int)> some_func;
Can I rewrite it in following way?
std::function<int(int begin, int end)> some_func;
It would be very nice, if it is standard compliant, because the type alone carries little information about the purpose of the parameter.
So far I've tested it in Visual Studio 2013 and it works. Edit: It works with gcc 4.8.1 too.
Yes, you can provide the parameter name. From paragraph §8.3.5/11 of the C++11 Standard:
An identifier can optionally be provided as a parameter name;
The same goes for pointer-to-function and pointer-to-member function type. Personally, I would use the identifier only if it expresses more clearly the intention of your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With