Relation between constexpr and pure functions

后端 未结 4 645
广开言路
广开言路 2020-12-11 00:16

Am I right, that:

  • Any function defined with constexpr is a pure function, and
  • Any pure function can be and must be defined with con
4条回答
  •  Happy的楠姐
    2020-12-11 00:49

    In addition to the previous answers: constexpr on a function restricts its implementation greatly: its body must be visible to the compiler (inline), and must consist only of a single return statement. I'd be surprised if you could implement sqrt() or sin() correctly and still meet that last condition.

提交回复
热议问题