C++ 如何获得n-嵌套向量的最内部类型?
我需要得到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::
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>
{ };
模板
结构基类型
:基本类型
{ };