Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use named parameters in std::function template signature type argument?

Tags:

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.

like image 347
ciechowoj Avatar asked Sep 08 '14 18:09

ciechowoj


1 Answers

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.

like image 93
David G Avatar answered Oct 05 '22 06:10

David G