我想知道我们是否可以做类似的事情
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的库Loki中有一个TypeLists的实现。我也认为Boost.MPL具有类似的构造:vector。