【发布时间】:2012-08-16 02:06:50
【问题描述】:
是否可以为所有常见的 STL 结构(例如,vector、set、map、...)编写一个值为 true 的类型特征?
首先,我想编写一个类型特征,对于 vector 为 true,否则为 false。我试过这个,但它没有编译:
template<class T, typename Enable = void>
struct is_vector {
static bool const value = false;
};
template<class T, class U>
struct is_vector<T, typename boost::enable_if<boost::is_same<T, std::vector<U> > >::type> {
static bool const value = true;
};
错误消息是template parameters not used in partial specialization: U。
【问题讨论】:
标签: c++ templates sfinae enable-if