是否有可能在得到執行就可以了mpl::find<seq,type>
後mpl::vector
的偏移?的boost :: MPL ::向量 - 讓爲類型的基本抵消
換句話說我想要做的編譯時間equavalent:
#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
類型都有一個常量type_trait<T>::ordinal
硬編碼的,我想如果可能避免這種情況。
重要提示,我也創建從向量boost::variant
,我看我可以通過執行運行時函數variant::which()
在序得到。但是,這需要我使用默認初始化值創建一個虛擬對象。這很不好。如果你知道其他方式使用變體,這也是我的問題的解決方案。
AAH的'iter'有一個'pos'元素?我找不到它的itterator概念文檔中http://www.boost.org/doc/libs/1_46_1/libs/mpl/doc/refmanual/iterators-concepts.html – 2011-05-18 11:50:57
雖然我無法找到一個POS' '成員,當我查看迭代器概念文檔時,它顯示在'mpl :: find'文檔的示例中(與您所顯示的代碼片段相同)。 – 2011-05-18 11:58:17
@Hassan賽義德:你可能有興趣在這兩個這個問題,其回答有關[無證ITER :: POS(http://stackoverflow.com/questions/5666394/is-mpl-pos-an-undocumented-metafunction) – 2011-05-18 12:04:53