The BOOST MPL find algorithm documentation has the following example:
typedef vector<char,int,unsigned,long,unsigned long> types; typedef find<types,unsigned>::type iter; ... BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 );
However, I cannot find the documentation for the iterator pos metafile. Can I use it reliably?
I would like to use it somehow like:
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; }
to save type information to a file along with the value itself.
EDIT
Thanks to Potatoswatter for the answer, it looks like this solution works:
template <typename S, typename T> struct pos : distance< typename begin<S>::type, typename find<S, T>::type > {}; ... unsigned typeID = pos<types, T>::value;
source share