single expression helper for compile-time enforced constexpr function evaluation possible?

前端 未结 3 744
无人共我
无人共我 2020-12-09 23:53

@cyberpunk_ is trying to achieve something and made some questions about it but all the chase boils down to this:

Is it possible to build a tool to enforce compile-ti

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 00:13

    Use std::integral_constant:

    int x = std::integral_constant::value;
    f(std::integral_constant::value);
    

    This code will not compile if g(n) is not evaluated at compile-time.

提交回复
热议问题