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

后端 未结 1 1233
攒了一身酷
攒了一身酷 2021-01-24 02:48

I am implementing functionality that provides the opportunity to translate the coordinates of the cells of the game board to the number of this cell.

This is what I\'m t

1条回答
  •  不要未来只要你来
    2021-01-24 03:01

    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.

    0 讨论(0)
提交回复
热议问题