Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a new function type expression format in C++11?

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?

like image 256
CTMacUser Avatar asked Apr 30 '13 03:04

CTMacUser


People also ask

What is a function declaration C++?

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.

What is return type in function header?

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.

Which is the default return type specifier in C++?

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 .

What is function declaration example?

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.


1 Answers

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.

like image 61
Xeo Avatar answered Oct 06 '22 16:10

Xeo