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

型リストの長さを取得するメタ関数です。

template <class... Args>
struct length {
    static const int value = sizeof...(Args);
};

template <class... Args>
struct length<tuple<Args...>> {
    static const int value = sizeof...(Args);
};
length<int, double, long>::value
→ 3
length<tuple<int, double, long>>::value
→ 3