是否有可能获得 a 的偏移量mpl::vector
执行完某个操作后mpl::find<seq,type>
on it ?
换句话说,我想做的编译时间相当于:
#include <vector>
#include <algorithm>
#include <iostream>
int main()
{
typedef std::vector<int> v_type;
v_type v_int(3);
v_int[0] = 1;
v_int[1] = 2;
v_int[2] = 3;
v_type::iterator it= std::find( v_int.begin() ,v_int.end(),3);
std::cout << it - v_int.begin() << std::endl;
}
如果失败的话,我输入mpl::vector
have a type_trait<T>::ordinal
const 硬编码,如果可能的话我想避免这种情况。
重要的提示,我也在创建一个boost::variant
从向量中,我发现我可以通过执行运行时函数来获取序号variant::which()
。但是,这需要我创建一个具有默认初始化值的虚拟对象。这是相当难看的。如果您知道使用变体执行此操作的其他方法,那也可以解决我的问题。
如果您正在寻找一种 indexOf 功能,我猜 Boost.MPL 文档中的示例涉及find
会成功的:
typedef vector<char,int,unsigned,long,unsigned long> types;
typedef find<types,unsigned>::type iter;
BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned > ));
BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)