我想知道我们是否可以做类似的事情
a.pushType<int>
a.pushType<std::string>
a.pushType<char>
所以我们可以调用
std::map<a.T1, a.T3> mymap;
std::map<a.T1, a.T2> mymap;
someClass<a.T1, a.T2, a.T3>
而且我不是在运行时而是在编译时需要它(以便在我的仅 header 库中提供它。)
C++03 和 Boost 有可能吗?
最佳答案
这是一种称为 TypeLists 的机制;据我所知,它最早是由 Andrei Alexandrescu 在 Modern C++ Design 中提出的。 Alexandrescu 的库中有一个 TypeLists 的实现,Loki .我还认为 Boost.MPL 具有类似的构造:vector .
关于C++:我们可以收集类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8306743/