Int (int, int) style type type type syntax

I remember that when using Boost.Spirit and to complement std :: function with C ++ 0x, you specify the type of function using syntax that does not use pointers, for example, when defining std::function<bool(int)> fn , whereas you will indicate the pointer as (bool(*)(int))fn .

Can someone tell me the name of this new syntax or any links to it or how to use it? This is similar to polymorphic function type syntax, which applies to functors as well, but I really don't know how to use it.

+6
source share
2 answers

bool(int) - type of function; bool(*)(int) - type of function pointer. In other words, if you define

 typedef bool(BF)(int); typedef bool(pBF*)(int); 

then BF* matches pBF .

The std::function template captures return and argument types through (variable) templates:

 template <typename R, typename ...Args> struct function { function(R(&f)(Args...)); // conceptually } 
+5
source

This is not a new syntax, although older compilers sometimes rejected it. It is simply a type of function compared to the type of a function pointer, similar to the type of arrays with respect to an array pointer.

The facts that there are no l-values โ€‹โ€‹of a function and that functions of r-values โ€‹โ€‹quickly decay into pointers to functions make them basically useless. Except, of course, patterns.

+4
source

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