Today I checked out Stroustrup's C++11 FAQ (modified April 7, 2013) and saw this at the end of the type-alias section:
typedef void (*PFD)(double); // C style
using PF = void (*)(double); // using plus C-style type
using P = [](double)->void; // using plus suffix return type
where a lambda introducer is used to start a general function type expression that uses a suffix-style return type. Is this official, or a dropped beta/wish-list feature? If it's official, how would it work for non-static member functions?
A function declaration tells the compiler about a function's name, return type, and parameters. A function definition provides the actual body of the function. The C++ standard library provides numerous built-in functions that your program can call.
The header includes the name of the function and tells us (and the compiler) what type of data it expects to receive (the parameters) and the type of data it will return (return value type) to the calling function or program.
Every function declaration and definition must specify a return type, whether or not it actually returns a value. If a function declaration does not specify a return type, the compiler assumes an implicit return type of int .
For example, if the my_function() function, discussed in the previous section, requires two integer parameters, the declaration could be expressed as follows: return_type my_function(int x, y); where int x, y indicates that the function requires two parameters, both of which are integers.
using P = [](double)->void;
is not official. Bjarne is known to be a bit careless in his FAQs.
What does work, however, are the following:
using P1 = auto(double) -> void;
using P2 = auto(*)(double) -> void;
Where P1
is a function type, and P2
is a function-pointer type. Maybe that was his intention.
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