noexcept关键字和_NOEXCEPT宏之间有什么区别? [英] What's the difference between the noexcept keyword and _NOEXCEPT macro?
问题描述
我是C ++的初学者,我正在学习某些C ++ 11功能.我注意到的一件事是,在Visual C ++ stdlib的某些部分中,作者使用了 _NOEXCEPT
宏而不是 noexcept
关键字.将鼠标悬停在宏上说 #define _NOEXCEPT noexcept
,所以我有点困惑它的意义是什么.两者之间有什么区别,我应该优先选择另一个吗?
我刚刚在GitHub上搜索了它,看起来像解决方案
_NOEXCEPT
不是标准宏.领先的下划线指出了这一点,它说这属于实现.
在Visual C ++编译器获得对C ++ 11中引入的 noexcept
关键字的支持之前,很可能将此宏定义为 throw()
.
也就是说,它最初是作为一种编写与多个版本的编译器兼容的代码的方式提供的.同样,可能会定义一个 CPPX_NORETURN
之类的宏,以使用编译器特定的方式来指示不返回函数,其中不支持C ++属性 [[noreturn]]
.依此类推.
I'm a beginner to C++ and I'm learning about some of the C++11 features. One thing I noticed was that in some parts of the Visual C++ stdlib, the authors used the _NOEXCEPT
macro instead of the noexcept
keyword. Hovering over the macro says #define _NOEXCEPT noexcept
, so I'm a bit confused what the point of it is. What's the difference between the two, and should I prefer one over the other?
EDIT: I just searched for it on GitHub and it looks like clang uses it as well, so it isn't a Visual C++ specific macro.
_NOEXCEPT
is not a standard macro. That's indicated by the leading underscore, which says this belongs to the implementation.
Most probably this macro was defined as throw()
until the Visual C++ compiler gained support for the noexcept
keyword introduced in C++11.
I.e., that it was originally provided as a means to write code that would be compatible with more than one version of the compiler. In a similar vein one might define a macro like CPPX_NORETURN
to use compiler-specific means to indicate a no-return function, where C++ attribute [[noreturn]]
is not supported. And so on.
这篇关于noexcept关键字和_NOEXCEPT宏之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!