constexpr error at compile-time, but no overhead at run-time

前端 未结 5 1211
小蘑菇
小蘑菇 2020-12-10 01:16

There is a well-known trick to cause a compile-time error in the evaluation of a constexpr function by doing something like this:

constexpr int          


        
5条回答
  •  悲哀的现实
    2020-12-10 01:30

    Instead of using a constexpr function, you should use static_assert. This lets you run an assertion at compile-time that has zero runtime cost.

提交回复
热议问题