C ++标准委员会倾向于回避在该语言中添加新的关键字,但C ++ 11并非如此。一些例子:
constexpr
decltype
thread_local
auto // New usage
noexcept
nullptr
static_assert
alignof
alignas
C ++ 14是否引入了新的关键字?
答案 0 :(得分:136)
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
......这是一种啰嗦的说“不”的方式。
(override
和final
是“具有特殊含义的标识符”,并在表3中列出; and
等是“替代表示......对于某些运算符和标点符号”和表5中列出了这些表。在C ++ 11和C ++ 14之间都没有更改表。)
答案 1 :(得分:85)
我发布这个答案是为了提供找到类似问题答案的工具。
标准草案目前保存在公共GitHub存储库中。这意味着你可以向GitHub本身提出这个问题!
关键字表位于文件source/lex.tex
上。如果你对它负责,我们可以发现last change to the keywords table发生在2011年8月(它实际上是第一次提交:自从repo在C ++ 11时间到来之后,该表没有改变正在最后确定。)
或者我们可以要求GitHub比较两种版本标准的选票:N3337和N3936。 diff between those two表示对lex.tex
的更改未在关键字表格中更改任何内容。
答案 2 :(得分:33)
C ++ 14不会添加任何新关键字。这并不令人惊讶,因为C ++ 14旨在作为对C ++ 11的小型升级,主要涉及清理错误并进行小的,低影响的改进。下一个重大变化可能是C ++' 17'我会再次期待新的关键词。
C ++标准委员会倾向于回避添加新关键字 对于语言而言,C ++ 11并非如此。
我认为值得考虑的是为什么委员会不愿意添加新的关键字(以及为什么你错误地将auto
列入你的列表)。新关键字的主要问题是,在C ++中,您无法使用关键字作为标识符,这意味着添加新关键字会破坏现有代码。然后,重新定位auto
并不会违反规则,因为现有代码无法使用auto
作为标识符 。
因此,为了接受一个新关键字,需要有一个理由超过与现有代码潜在冲突的成本,并且没有合理的方法在没有新关键字的情况下实现同样的事情。就C ++ 11而言,委员会接受了一些需要新关键词的提案,因为他们觉得这些好处超过了成本,并不是因为他们不讨厌添加新的关键词。
这也是为什么,如果你向下看你给出的列表,每个都是复合关键字,因为这样可以减少他们与现有标识符发生冲突的可能性。