2008-08-14

Variadic TemplatesでN番目のTemplate Parameter Packsの型を得る方法

規格にはN1704で示されているようなN番目の型を得る方法が入っていない。すると、こうするのだろうか。

template < size_t N, typename Head, typename... Tail >
struct nth_type : public nth_type<N-1, Tail...>
{ } ;

template < typename Head, typename... Tail >
struct nth_type< 1, Head, Tail... >
{
    typedef Head type ;
} ;

No comments:

Post a Comment

You can use some HTML elements, such as <b>, <i>, <a>, also, some characters need to be entity referenced such as <, > and & Your comment may need to be confirmed by blog author. Your comment will be published under GFDL 1.3 or later license with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.