【发布时间】:2023-03-06 07:45:02
【问题描述】:
假设我有许多原子结构,每个都有一个inner_type:
struct Atomic1{
using inner_type = int;
};
struct Atomic2{
using inner_type = double;
};
struct Atomic3{
using inner_type = bool;
};
...
我的客户端类是一个可变参数模板,可以使用上述原子类中的一个或多个:
template<class ...AtomicTypeArgPack>
class MyclassAcceptingAtomicTypes;
我有一个相关的泛型类,它接受Atomic*::inner_type 作为模板参数:
template<class ...InnerTypeArgPack>
class MyclassAcceptingInnerTypes;
我的特定 api 类已定义,但指定了几个模板类型:
using my_first_class_t = MyclassAcceptingAtomicTypes<Atomic1, Atomic2>;
对于每个特定的类,我还有另一类内部类型:
using my_first_class_inner_types_t = MyclassAcceptingInnerTypes<Atomic1::inner_type , Atomic2::inner_type >;
有没有办法使用模板元编程/元函数从第一个声明(my_first_class_t)自动生成第二种类型(即my_first_class_inner_types_t)?
【问题讨论】:
标签: c++ c++11 variadic-templates template-meta-programming typetraits