is_defined constexpr function
我需要知道在指定noexcept说明符时是否定义了ndebug。我按照constexpr函数的思路思考:
| 1 2 3 4 5 6 7 8 9 | constexpr inline bool is_defined() noexcept { return false; } constexpr inline bool is_defined(int) noexcept { return true; } | 
然后像这样使用:
| 1 2 3 4 | void f() noexcept(is_defined(NDEBUG)) { // blah, blah } | 
号
标准库或语言是否已经为此提供了一个工具,这样我就不会重新发明轮子了?
   是的,使用
| 1 2 3 4 5 6 7 8 9 | #ifdef  NDEBUG using is_ndebug = std::true_type; #else using is_ndebug = std::false_type; #endif void f() noexcept(is_ndebug{}) { // blah, blah } | 
   无数的研究或其他类似的方式:(一
   如果你是只读的interested在
| 1 2 3 4 | void f() noexcept(noexcept(assert((throw true,true)))) { // ... } | 
这是,当然,不安necessarily改良:) </P >