c 11 – is_defined constexpr函数
发布时间:2020-12-16 09:57:04  所属栏目:百科  来源:网络整理 
            导读:我需要知道在指定noexcept说明符时是否定义了NDEBUG.我正在考虑这个constexpr功能: constexpr inline bool is_defined() noexcept{ return false;}constexpr inline bool is_defined(int) noexcept{ return true;} 然后使用它像: void f() noexcept(is_def
                
                
                
            | 
                         
 我需要知道在指定noexcept说明符时是否定义了NDEBUG.我正在考虑这个constexpr功能: 
  
  
  
constexpr inline bool is_defined() noexcept
{
  return false;
}
constexpr inline bool is_defined(int) noexcept
{
  return true;
} 
 然后使用它像: void f() noexcept(is_defined(NDEBUG))
{
  // blah,blah
} 
 标准库或语言是否已经为此提供了便利,以便我不会重新发明轮子? 解决方法
 如果您只对NDEBUG感兴趣,这相当于测试assert()是否评估它的参数.在这种情况下,您可以使用: 
  
  
  
        void f() noexcept(noexcept(assert((throw true,true))))
{
    // ...
} 
 当然,这不一定是改进:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
