C++标准委员会倾向于避免在语言中添加新的关键字,但对于C++11,情况并非如此。下面是一些例子:
constexpr
decltype
thread_local
auto // New usage
noexcept
nullptr
static_assert
alignof
alignas
C++14中是否引入了新的关键字?
发布于 2014-08-19 18:07:44
N3936 (C++14)中的表4(关键字):
alignas continue friend register true
alignof decltype goto reinterpret_cast try
asm default if return typedef
auto delete inline short typeid
bool do int signed typename
break double long sizeof union
case dynamic_cast mutable static unsigned
catch else namespace static_assert using
char enum new static_cast virtual
char16_t explicit noexcept struct void
char32_t export nullptr switch volatile
class extern operator template wchar_t
const false private this while
constexpr float protected thread_local
const_cast for public throw
N3337 (C++11)中的表4:
alignas continue friend register true
alignof decltype goto reinterpret_cast try
asm default if return typedef
auto delete inline short typeid
bool do int signed typename
break double long sizeof union
case dynamic_cast mutable static unsigned
catch else namespace static_assert using
char enum new static_cast virtual
char16_t explicit noexcept struct void
char32_t export nullptr switch volatile
class extern operator template wchar_t
const false private this while
constexpr float protected thread_local
const_cast for public throw
...which是一种冗长的说“不”的方式。
(override
和final
是“具有特殊含义的标识符”,在表3中列出;and
等是"alternative representations...for某些运算符和标点符号“,在表5中列出。这两个表都没有在C++11和C++14之间更改。)
发布于 2014-08-20 01:04:09
我张贴这个答案是为了给出工具来寻找类似问题的答案。
标准草案目前保存在公共GitHub存储库中。这意味着你可以问GitHub本身这个问题!
关键字表位于文件source/lex.tex
上。如果你将其归咎于此,我们可以发现last change to the keywords table发生在2011年8月(这实际上是第一次提交:自从回购在C++11最终完成时上线以来,该表一直没有改变)。
或者,我们可以要求GitHub比较标准的两个版本: N3337和N3936的投票结果。一个diff between those two表明对lex.tex
的更改并没有改变keywords表中的任何内容。
发布于 2014-08-20 02:51:14
C++14不会添加新的关键字。这并不奇怪,因为C++14是对C++11的一个小升级,主要涉及清理错误和进行小的、影响小的改进。下一个主要的变化可能是C++'17‘,我期待着新的关键字再次出现。
C++标准委员会倾向于避免向语言中添加新的关键字,但对于C++11,情况并非如此。
我认为值得考虑的是,为什么委员会不愿添加新的关键字(巧合的是,为什么您在列表中包含auto
是错误的)。新关键字的主要问题是,在C++中不能使用关键字作为标识符,这意味着添加新关键字会破坏现有代码。因此,改变auto
的用途并不会违反他们的规则,因为无论如何,现有的代码都不能使用auto
作为标识符。
因此,为了接受一个新的关键字,需要一个合理的理由来超过与现有代码的潜在冲突的成本,并且没有合理的方法在没有新关键字的情况下实现相同的事情。在C++11的案例中,委员会接受了一些需要新关键字的建议,因为他们觉得好处大于成本,而不是因为他们不讨厌添加新关键字。
这也是为什么,如果你看一下你给出的列表,每一个都是一个复合关键字,因为这减少了它们与现有标识符冲突的机会。
https://stackoverflow.com/questions/25380599
复制相似问题