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++ 如何获得n-嵌套向量的最内部类型?_C++_Templates_Vector_Nested - Fatal编程技术网

C++ 如何获得n-嵌套向量的最内部类型?

C++ 如何获得n-嵌套向量的最内部类型?,c++,templates,vector,nested,C++,Templates,Vector,Nested,我需要得到n-嵌套向量的内部类型。例如: type a; //base_type of a = type std::vector<type> b; //base_type of b = type std::vector<std::vector<type>> c;//base_type of c = type a型//a=类型的基本类型 std::载体b//b=类型的基本类型 std::

我需要得到n-嵌套向量的内部类型。例如:

type a;                          //base_type of a = type
std::vector<type> b;             //base_type of b = type
std::vector<std::vector<type>> c;//base_type of c = type
a型//a=类型的基本类型
std::载体b//b=类型的基本类型
std::向量c//c=类型的基本类型
等等。我尝试使用包装器,但这会导致编译器错误

template<typename T1>
struct base_type : T1::value_type { };

template<typename T1>
struct base_type<std::vector<T1>> {
    using type = typename base_type<T1>::value_type;
};
模板
结构基类型:T1::值类型{};
样板
结构基类型{
使用type=typename base\u type::value\u type;
};

两种情况都错误

您的基本情况应该是非
向量
情况。对于非
向量
,没有
::值\u类型
。您只需要以下类型:

template <typename T>
struct base_type {
    using type = T;
};
我们可以简化为:

template<typename T>
struct base_type<std::vector<T>> 
: base_type<T>
{ };
模板
结构基类型
:基本类型
{ };

您的两个案例都是错误的

您的基本情况应该是非
向量
情况。对于非
向量
,没有
::值\u类型
。您只需要以下类型:

template <typename T>
struct base_type {
    using type = T;
};
我们可以简化为:

template<typename T>
struct base_type<std::vector<T>> 
: base_type<T>
{ };
模板
结构基类型
:基本类型
{ };