What is (for search) the name for this syntax ...?

typedef std::function<bool(int)> MyFunction; 

This syntax is notation for the argument template template bool(int) - does it have a name? I tried to read the C ++ standard about this syntax and did not know what to look for.

Obviously, using it in other contexts seems to fail.

 typedef bool(int) MyFunctionType; // does not work. 

So, I guess somewhere there is a special chapter about this syntax ...

Thanks.

+6
source share
2 answers

I do not know about this common name. In the standard, it was called the type identifier after it created the grammar.

An identifier of type bool(int) calls a function of type (int) that returns bool ".

It does not work with typedef (the syntax of the regular declaration is used instead), but the alias declared with using uses the type identifier:

 using MyFunctionType = bool(int); 
+9
source

N4140 calls the bool(int) function type in [dcl.fct]. As indicated in another answer, this is a type identifier:

[dcl.name] / 1 To explicitly specify type conversions, and as an argument to sizeof , alignof , new or typeid , the name type must be specified. This can be done with a type identifier that is syntactically declared for a variable or function of that type that omits the name of the object.

+2
source

Source: https://habr.com/ru/post/982849/


All Articles