Boost.MultiIndex - indexed_by

multi_index_containerのインデックスリストを指定するためにboost::multi_index::indexed_byを使用しますが

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/ordered_index.hpp>

using namespace boost::multi_index;

typedef multi_index_container< 
    int,
    indexed_by<
        random_access<>,
        ordered_unique<identity<int> >
    >
> Container;

int main() {}

indexed_byは、MPLのRandom Access SequenceExtensible Sequenceとして使用することができます。

#include <type_traits>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/find.hpp>
#include <boost/mpl/erase.hpp>
#include <boost/mpl/int.hpp>

using namespace boost;
using namespace boost::multi_index;

typedef
    indexed_by<
        random_access<>,
        ordered_unique<identity<int> >
    >
Index;

typedef multi_index_container<int, Index> Container;

typedef ordered_unique<identity<int> > x;
static_assert(std::is_same<mpl::at<Index, mpl::int_<1>>::type, x>::value, "failed at");

typedef mpl::erase<Index, mpl::find<Index, x>::type>::type erased_list;
static_assert(mpl::size<erased_list>::value == 1, "failed erase");

int main() {}

実装としては、indexed_byはmpl::vectorを継承しているだけです。