【发布时间】:2015-05-26 14:49:13
【问题描述】:
以下不编译
#include <iostream>
#include <type_traits>
// forward declaration of a type template
template<class T, class Alloc = std::allocator<T>> class std::vector;
template<class T>
struct is_vector : std::false_type { };
// using the forward declared type template
template<class T, class Alloc>
struct is_vector<std::vector<T, Alloc>> : std::true_type { };
#include <vector>
int main()
{
std::cout << is_vector<std::vector<int>>::value << std::endl;
}
我想确保前向声明的类型模板(在vector 之上)在专业化上下文中实际上是不可用的,并且这不是一个错误的实现。另外为什么会发生这种情况?我不想创建vector<> 类型的对象,仅将其用作在专业之间分派的标签; 在实例化点包含<vector> 不够(is_vector<> 的调用站点)?
【问题讨论】:
-
你的前向声明是错误的。
标签: c++ templates template-meta-programming