【发布时间】:2011-01-10 14:34:31
【问题描述】:
我想特化一个声明为的模板函数:
template<typename Type> Type read(std::istream& is);
然后我有很多静态实现
static int read_integer(std::istream& is);
a.s.o.现在我想做一个宏,这样读取的特化就很简单了:
SPECIALIZE_READ(read_integer)
所以我想我会采用 boost::function_traits 的方式并将 SPECIALIZE_READ 声明为:
#define SPECIALIZE_READ(read_function) \
template<> boost::function_traits<read_function>::result_type read(std::istream& is) { \
return read_function(is); \
}
但是 VC++ (2008) 编译器抱怨:“boost::function_traits”:“read_integer”不是参数“函数”的有效模板类型参数
想法?
【问题讨论】:
-
那是因为您将值(read_function)作为类型传递。在 C++03 中它不会那样工作。在 C++0x 中,您可以使用 decltype(read_function)。
-
嗯,是吗?我还应该通过什么?过去我已经成功地将 function_traits 与类方法一起使用,我也将它与函数一起使用,但我不知道为什么它在这种情况下不起作用......
标签: c++ function boost typetraits