int(int,int)样式模板函数类型语法

nor*_*lli 6 c++ syntax templates function-pointers function

我记得当使用Boost.Spirit时,对于C++ 0x的std :: function添加,你可以通过使用不使用指针的语法来指定函数类型,比如在定义时std::function<bool(int)> fn,你可以使用类似的指针(bool(*)(int))fn.

谁能告诉我这个新语法的名称或对此的任何引用,或如何使用它?它看起来像一个多态函数类型语法也适用于仿函数,但我真的不知道如何使用它.

Ker*_* SB 5

bool(int)是函数的类型; bool(*)(int)是函数指针的类型.换句话说,如果你定义

typedef bool(BF)(int);
typedef bool(pBF*)(int);
Run Code Online (Sandbox Code Playgroud)

然后BF*是一样的pBF.

std::function模板通过捕捉(可变参数)模板返回和参数类型:

template <typename R, typename ...Args> struct function
{
  function(R(&f)(Args...)); // conceptually
}
Run Code Online (Sandbox Code Playgroud)