Here is the code {{{ #include <iostream> #include <boost/mpl/int.hpp> #include <boost/mpl/transform.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/for_each.hpp> #include <boost/mpl/find.hpp> using namespace boost::mpl; typedef boost::mpl::vector<int_<3>, int_<4>, int_<9>, int_<10> > my_vec; struct add_index_wrap{ template<typename T> struct apply{ struct A{ typedef T type; typedef typename boost::mpl::find<my_vec, T>::type found_type; typedef typename boost::mpl::int_<found_type::pos::value> index; }; typedef A type; }; }; struct print{ template<typename T> void operator()(T t){ std::cout<<"Index:"<<T::index::value<<std::endl; std::cout<<"Value:"<<T::type::value<<std::endl; } }; int main() { typedef transform< my_vec, add_index_wrap >::type my_vec_2; boost::mpl::for_each<my_vec_2>( print() ); } }}} === References #[[http://www.boost.org/doc/libs/1_59_0/libs/mpl/doc/refmanual/find.html|boost::mpl::find]] #[[http://www.boost.org/doc/libs/1_59_0/libs/mpl/doc/refmanual/transform.html|boost::mpl::transform]]