boost::mpl::vector - 获取类型的基本偏移量
问题描述
在对 mpl::find<seq,type>
执行 mpl::find<seq,type>
之后,是否可以获得 mpl::vector
的偏移量?
Is it possible to get at the offset of a mpl::vector
after performing a mpl::find<seq,type>
on it ?
换一种说法,我想做以下等价的编译时间:
Put differently I want to do the compile time equavalent of:
如果不这样做,我在 mpl::vector
中的类型有一个 type_trait<T>::ordinal
const 硬编码,如果可能的话,我想避免这种情况.
Failing this, my types in mpl::vector
have a type_trait<T>::ordinal
const hard-coded, I would like to avoid this if possible.
重要提示,我还从向量中创建了一个 boost::variant
,我发现我可以通过执行运行时函数 来获得序数变体::which()
.但是,这需要我创建一个具有默认初始化值的虚拟对象.这是相当难看的.如果您知道使用变体的其他方法,那也可以解决我的问题.
Important Note, I am also creating a boost::variant
from the vector, and I see I can get at the ordinal by performing a runtime function variant::which()
. However, this requires I create a dummy object with default-initialized values. This is quite uggly. If you know some other way of doing it with variant, that would be a solution to my problem as well.
推荐答案
如果您正在寻找的是一种 indexOf 功能,我猜 Boost.MPL 文档中关于 find
的示例将做这个伎俩:
If what you're looking for is a kind of indexOf feature, I guess the example from Boost.MPL doc concerning find
will do the trick:
这篇关于boost::mpl::vector - 获取类型的基本偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!