int(int,int)样式模板函数类型语法 [英] int(int, int) style template function type syntax
问题描述
我记得当使用Boost.Spirit和std ::函数添加到C ++ 0x时,你使用不使用指针的语法指定函数类型,就像在定义 std :: function< bool(int)> fn
,而你将会投射(bool(*)(int))fn
。
I remember that when using Boost.Spirit and for the std::function addition to C++0x, you specify the function type by using a syntax that doesn't use pointers, like in defining std::function<bool(int)> fn
, whereas you would cast a pointer like (bool(*)(int))fn
.
任何人都可以告诉我这个新的语法的名称或任何参考,或如何使用它?它似乎是一个多态函数类型语法,也适用于函子,但我真的不知道如何使用它。
Can anyone tell me the name of this new syntax or any references on this, or how to use it? It seems like a polymorphic function type syntax that applies for functors as well, but I don't really know how to use it.
推荐答案
p> bool(int)
是函数的类型; bool(*)(int)
是函数指针的类型。换句话说,如果你定义
bool(int)
is the type of the function; bool(*)(int)
is the type of the function pointer. In other words, if you define
typedef bool(BF)(int);
typedef bool(pBF*)(int);
然后 BF *
code> pBF 。
then BF*
is the same as pBF
.
std :: function
模板捕获通过(可变参数)模板返回参数类型:
The std::function
template captures the return and argument types via (variadic) templates:
template <typename R, typename ...Args> struct function
{
function(R(&f)(Args...)); // conceptually
}
这篇关于int(int,int)样式模板函数类型语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!