【发布时间】:2020-01-23 19:30:11
【问题描述】:
假设我有:
struct M1 { static constexpr int T = 3; }
struct M2 { static constexpr int T = 8; }
struct M3 { static constexpr int T = 19; }
这确实是两个相互关联的问题:
- 存储所有 M 类型的列表以便以后我不必重复自己的最佳方式是什么?
在 Fantasy-c++ 中:using AllMs = <M1, M2, M3>;
- 鉴于该列表,我如何获得 M::T 列表(但作为类型)?
在 Fantasy-c++ 中:using AllMTs = AllMs::T ...;(可能使用 std::integral_type)
例如,我可以像这样从所有 O 乘以继承:
template <class... M> class K: public O<M>... { }
template <typename ...P> struct ParameterPackApplicator {
template <template <typename...> typename T> using apply = T<P...>;
};
using AllM = ParameterPackApplicator<M1, M2, M3>;
using MultiplyInheritedThing = AllM::apply<K>;
...但我似乎无法弄清楚如何获得所有 M::T 的类型列表...
【问题讨论】:
-
“我不必重复自己”是什么意思?你想避免什么重复?
-
还有2.不太清楚
M::T是什么? -
T实际上是什么?变量、类型或函数? -
我以后想多继承一些东西:class S: public O
。并获取这些依赖类型。还有其他的…… -
为什么要继承?这些类型只有一个静态成员,它们都具有相同的名称
标签: c++ templates template-meta-programming