Error C1202 (stack overflow) when recursively computing a templated value or function when using a conditional operator

谁说胖子不能爱 提交于 2019-12-02 04:42:47

The ternary conditional in this case is not equivalent to if statement because it is a constexpr if statement.

With constexpr if statement,

If a constexpr if statement appears inside a templated entity, and if condition is not value-dependent after instantiation, the discarded statement is not instantiated when the enclosing template is instantiated .

But with the ternary conditional, the templates are always instantiated. This leads to infinite recursion.

Note that if you replace the constexpr if with normal if you get the same error. See DEMO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!