可変引数テンプレートでの型リスト - take

型リストから先頭N個の型を取り出すメタ関数です。

template <int N, class Seq>
struct take;

template <int N, class Head, class... Tail>
struct take<N, tuple<Head, Tail...>> {
    typedef
        typename concat<tuple<Head>,
                        typename take<N-1, tuple<Tail...>>::type
                 >::type
    type;
};

template <class Head, class... Tail>
struct take<1, tuple<Head, Tail...>> {
    typedef tuple<Head> type;
};

template <class Head, class... Tail>
struct take<0, tuple<Head, Tail...>> {
    typedef tuple<> type;
};
take<3, tuple<int, double, long, char, void*>>::type
→ tuple<int, double, long>