C ++:我们可以收集类型吗? [英] C++: can we collect types?
本文介绍了C ++:我们可以收集类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我们是否可以做像
I wonder if we could do something like
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>
我需要它不是在运行时,但在编译时)
And I need it not at run time but at compile time (for providing it in my header only library.)
是否可以使用C ++ 03和Boost?
Is it possible with C++03 and Boost?
推荐答案
这是一个名为TypeLists的机制;据我所知,这是由Andrei Alexandrescu在 Modern C ++ Design 中首次提出的。在Alexandrescu的库中有一个类型列表的实现, Loki 。我也认为Boost.MPL有一个类似的结构:向量。
That's a mechanism called TypeLists; as far as I know it was first proposed by Andrei Alexandrescu in Modern C++ Design. There's an implementation of TypeLists in Alexandrescu's library, Loki. I also think Boost.MPL has a similar construct: the vector.
这篇关于C ++:我们可以收集类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文