std::make_inedex_sequence
templatestruct index_sequence{}; template struct make_index_sequence : public make_index_sequence { }; template struct make_index_sequence<0, M...>: public index_sequence { };
这种写法的核心是M...起始为空,用头插法由N-1递归地扩展出0,1,2,..., N-1序列。以make_index_sequence<3>为例,递归扩展过程如图所示:
网上我还看到另一种方法,采用尾插法:
templatestruct index_sequence{}; template struct AppendNewValue; template struct AppendNewValue { using type = index_sequence; } template struct make_index_sequence { using type = typename AppendNewValue ::type, N-1>::type; } template<> struct make_index_sequence<0> { using type = index_sequence<>; }



