MPL Sequence を slice

パッと見なかったので書いてみた。

#include <boost/mpl/vector.hpp>
#include <boost/mpl/begin.hpp>
#include <boost/mpl/iterator_range.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/advance.hpp>

namespace mpl = boost::mpl;

template<typename Seq, typename N, typename M>
struct slice :
    mpl::iterator_range<
        typename mpl::advance<typename mpl::begin<Seq>::type, N>::type,
        typename mpl::advance<typename mpl::begin<Seq>::type, M>::type
    >
{};

template<typename Seq, int N, int M>
struct slice_c : slice<Seq, mpl::int_<N>, mpl::int_<M> >{};


#include <boost/mpl/assert.hpp>
#include <boost/mpl/equal.hpp>

typedef mpl::vector<char, int, float, double, void> seq;

BOOST_MPL_ASSERT(( mpl::equal<
    slice_c<seq, 1, 4>::type,
    mpl::vector<int, float, double>
> ));

int main(){}


この手の Algorithms って需要あるんでしょうか。
たまに無性に欲しくなります。


[boost]
ver 1.46.1