How to use static_assert for constexpr function arguments in C++?

后端 未结 3 1251
野性不改
野性不改 2020-12-20 13:16

I have several brief constexpr functions in my libraries that perform some simple calculations. I use them both in run-time and compile-time contexts.

I

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-20 13:41

    I believe that assert will work for you once g++ implements N3652, Relaxing constraints on constexpr functions. Currently, this status page indicates that this has not yet been implemented.

    assert does work (in constexpr functions) on the current clang compiler shipped by Apple, with -std=c++1y.

    At this time, I see nothing in the standard that assures one that assert will work in constexpr functions, and such an assurance would be a welcome addition to the standard (at least by me).

    Update

    Richard Smith drew my attention to LWG 2234 submitted by Daniel Krügler which is attempting to create the assurance I refer to above.

提交回复
热议问题