相关疑难解决方法(0)

如何写一个类型特征`is_container`或`is_vector`?

是否可以写一个类型的特点,它的值是所有常见的STL结构真(例如vector,set,map,...)?

首先,我想编写一个类型特征,对于a vector和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;
};
Run Code Online (Sandbox Code Playgroud)

错误消息是template parameters not used in partial specialization: U.

c++ templates sfinae enable-if

23
推荐指数
5
解决办法
2万
查看次数

标签 统计

c++ ×1

enable-if ×1

sfinae ×1

templates ×1