里面有下面的示例代码BOOST MPL 文档find算法 http://www.boost.org/doc/libs/1_46_1/libs/mpl/doc/refmanual/find.html:
typedef vector<char,int,unsigned,long,unsigned long> types;
typedef find<types,unsigned>::type iter;
...
BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
但是,我找不到迭代器的文档pos
元功能。我可以可靠地使用它吗?
我想以某种方式使用它:
typedef vector<type1, type2, type3> types;
template <typename T>
void File::write(T value) {
BOOST_MPL_ASSERT((contains<types, T>));
unsigned typeID = find<types, T>::type::pos::value;
fstr << typeID << value;
}
将类型信息与值本身一起存储到文件中。
EDIT
感谢 Potatoswatter 的回答,这个解决方案似乎有效:
template <typename S, typename T>
struct pos : distance< typename begin<S>::type, typename find<S, T>::type >
{};
...
unsigned typeID = pos<types, T>::value;