草庐IT

NumberGeneration

全部标签

c++ - 编译时间递归和条件

我正在阅读对"Printing1to1000withoutlooporconditionals"的回复,我想知道为什么有必要在顶部答案中包含NumberGeneration的特殊情况。如果我删除它并在模板中添加对N==1的检查(下面的代码),代码会因“模板实例化深度超过最大值”而无法编译,但我不确定为什么。条件语句在编译时的处理方式是否不同?#includetemplatestructNumberGeneration{staticvoidout(std::ostream&os){if(N==1){os::out(os);os::out(std::cout);}