Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 转发声明的类型模板能否参与模板专门化?_C++_Templates_Template Meta Programming - Fatal编程技术网

C++ 转发声明的类型模板能否参与模板专门化?

C++ 转发声明的类型模板能否参与模板专门化?,c++,templates,template-meta-programming,C++,Templates,Template Meta Programming,以下内容不可编译 #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

以下内容不可编译

#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;
}
#包括
#包括
//类型模板的转发声明
模板类std::vector;
模板
结构是_向量:std::false_类型{};
//使用前向声明的类型模板
模板
结构是_向量:std::true_类型{};
#包括
int main()
{

std::cout转发标准库容器的声明(如果您设法编译它),因此对于
std::vector
,您必须在定义
is\u vector
之前包含

对于您自己的类型,您可以这样做:

// forward declaration of a type template
namespace my {
    template<class T, class Alloc> class vector; 
}

template<class T>
struct is_vector : std::false_type { };

// using the forward declared type template
template<class T, class Alloc>
struct is_vector<my::vector<T, Alloc>> : std::true_type { };

namespace my {
    template<class T, class Alloc = std::allocator<T>> class vector {}; 
}
//类型模板的转发声明
名称空间我的{
模板类向量;
}
模板
结构是_向量:std::false_类型{};
//使用前向声明的类型模板
模板
结构是_向量:std::true_类型{};
名称空间我的{
模板类向量{};
}

转发标准库容器的声明(如果您设法编译它),因此对于
std::vector
,您必须在定义
is\u vector
之前包含

对于您自己的类型,您可以这样做:

// forward declaration of a type template
namespace my {
    template<class T, class Alloc> class vector; 
}

template<class T>
struct is_vector : std::false_type { };

// using the forward declared type template
template<class T, class Alloc>
struct is_vector<my::vector<T, Alloc>> : std::true_type { };

namespace my {
    template<class T, class Alloc = std::allocator<T>> class vector {}; 
}
//类型模板的转发声明
名称空间我的{
模板类向量;
}
模板
结构是_向量:std::false_类型{};
//使用前向声明的类型模板
模板
结构是_向量:std::true_类型{};
名称空间我的{
模板类向量{};
}

您的转发声明是错误的。您的转发声明是错误的。我在VS2012中编译了一个有问题的代码变体(在gcc中失败),因此对整个情况感到困惑。对于InfoNX,我在VS2012中编译了一个有问题的代码变体(在gcc中失败),所以对整个情况感到困惑。Thnx获取信息