【发布时间】:2017-01-03 22:36:09
【问题描述】:
我有一个类似于std::integer_sequence 的课程Index:
template<std::size_t... NValues>
struct Index { };
我想用序列 N-1, N-2, ..., 2, 1, 0 填充它。
template<std::size_t N>
struct MakeIndex
{
private:
template<std::size_t I, std::size_t... NIndexValues>
struct _Make;
public:
using Type = typename _Make<N>::Type;
private:
template<std::size_t I, std::size_t... NIndexValues>
struct _Make
{
using Type = typename _Make<I - 1, NIndexValues..., I - 1>::Type;
};
template<std::size_t... NIndexValues>
struct _Make<0, NIndexValues...>
{
using Type = Index<NIndexValues...>;
};
};
int main()
{
using T = MakeIndex<5>::Type;
}
在clang编译器(3.7.0)上,它产生
致命错误:递归模板实例化超出最大深度 256 个
它在 VS 和 GCC 上运行良好。也许我做错了什么?还是编译器的bug?
【问题讨论】:
标签: c++11 recursion variadic-templates clang++