热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

c++14是否在c++中添加了新的关键字?-IsC++14addingnewkeywordstoC++?

TheC++StandardsCommitteetendstoshyawayfromaddingnewkeywordstothelanguage,yetwithC++

The C++ Standards Committee tends to shy away from adding new keywords to the language, yet with C++11 that was not the case. Some examples:

c++标准委员会倾向于回避在语言中添加新的关键字,但是使用c++ 11却不是这样。一些例子:

constexpr
decltype
thread_local
auto // New usage
noexcept
nullptr
static_assert
alignof
alignas

Are there any new keywords introduced with C++14?

有什么新的关键字引入c++ 14吗?

3 个解决方案

#1


136  

Table 4 (Keywords) in N3936 (C++14):

表4(关键词)N3936 (c++ 14):

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

Table 4 in N3337 (C++11):

表4 N3337 (C++11):

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 is a long-winded way of saying "no".

…这是一个冗长的说“不”的方式。

(override and final are "identifiers with special meaning" and are listed in Table 3; and etc. are "alternative representations...for certain operators and punctuators" and are listed in Table 5. Neither table changed between C++11 and C++14.)

(override和final是“具有特殊含义的标识符”,列于表3中;等等是“替代表征……”表5列出了某些操作符和标点符号。这两个表在c++ 11和c++ 14之间都没有变化。

#2


85  

I'm posting this answer for the sake of giving tools for finding answers to similar questions.

我发布这个答案是为了提供工具来寻找类似问题的答案。

The standard draft is currently kept in a public GitHub repository. That means you can ask this question to GitHub itself!

标准草案目前保存在一个公开的GitHub存储库中。这意味着你可以问GitHub自己这个问题!

The keywords table is on the file source/lex.tex. If you do a blame on it, we can find that the last change to the keywords table took place back in August 2011 (it's actually the first commit: that table hasn't changed since the repo went live around the time C++11 was being finalised).

关键字表位于文件源/lex.tex上。如果你对此负责,我们可以发现,关键字表的最后一个变更发生在2011年8月(这实际上是第一次提交:自从repo在C++11事件结束之后,这个表一直没有改变)。

Alternatively we can ask GitHub to compare the two drafts that were sent for ballot for both versions of the standard: N3337 and N3936. A diff between those two shows that the changes to lex.tex did not change anything in the keywords table.

或者,我们可以要求GitHub比较两种版本的投票结果:N3337和N3936。这两者之间的差异表明lex的变化。tex没有更改关键字表中的任何内容。

#3


33  

No new keywords will be added with C++14. This is unsurprising as C++14 is intended as a small upgrade to C++11 mainly involved in cleaning up bugs and making small, low impact, improvements. The next major change is likely to be C++'17' where I would expect new keywords once more.

没有新的关键字将添加到c++ 14。这并不奇怪,因为c++ 14打算作为c++ 11的小型升级,主要用于清理bug并进行小的、低影响的改进。下一个主要的变化可能是c++的“17”,在这里我将再次期待新的关键字。

The C++ Standards Committee tends to shy away from adding new keywords to the language, yet with C++11 that was not the case.

c++标准委员会倾向于避免在语言中添加新的关键字,但是c++ 11不是这样的。

I think it's worth considering why the committee shies away from adding new keywords (and co-incidentally why you are wrong to include auto on your list). The main problem with new keywords is that in C++ you can't use a keyword as an identifier which means that adding a new keyword breaks existing code. Repurposing auto, then, doesn't break their rule because no existing code could use auto as an identifier anyway.

我认为值得考虑的是,为什么委员会不愿增加新的关键词(顺便说一下,为什么你把auto包括在你的列表中是错误的)。新关键字的主要问题是,在c++中,不能使用关键字作为标识符,这意味着添加新关键字会破坏现有代码。因此,重新利用auto并不会破坏他们的规则,因为任何现有代码都不能使用auto作为标识符。

So in order to accept a new keyword there needs to be a justification that outweighs the cost of a potential clash with existing code and no sensible way to implement the same thing without a new keyword. In the case of C++11, the committee accepted a few proposals that required new keywords since they felt that that the benefit outweighed the cost not because they don't hate to add new keywords.

因此,为了接受一个新的关键字,需要有一个比潜在的与现有代码冲突的代价更大的理由,并且没有一个没有新关键字的合理方法来实现相同的东西。在c++ 11的例子中,委员会接受了一些需要新的关键字的建议,因为他们认为好处大于成本,而不是因为他们不喜欢添加新的关键字。

It's also why, if you look down the list you gave, each one is a compound keyword since that reduces the chance that they'll clash with existing identifiers.

这也是为什么,如果您查找您给出的列表,每个都是一个复合关键字,因为这减少了它们与现有标识符冲突的可能性。


推荐阅读
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文介绍了Java并发库中的阻塞队列(BlockingQueue)及其典型应用场景。通过具体实例,展示了如何利用LinkedBlockingQueue实现线程间高效、安全的数据传递,并结合线程池和原子类优化性能。 ... [详细]
  • 本文介绍了如何使用JQuery实现省市二级联动和表单验证。首先,通过change事件监听用户选择的省份,并动态加载对应的城市列表。其次,详细讲解了使用Validation插件进行表单验证的方法,包括内置规则、自定义规则及实时验证功能。 ... [详细]
  • 深入解析JVM垃圾收集器
    本文基于《深入理解Java虚拟机:JVM高级特性与最佳实践》第二版,详细探讨了JVM中不同类型的垃圾收集器及其工作原理。通过介绍各种垃圾收集器的特性和应用场景,帮助读者更好地理解和优化JVM内存管理。 ... [详细]
  • 深入解析Android自定义View面试题
    本文探讨了Android Launcher开发中自定义View的重要性,并通过一道经典的面试题,帮助开发者更好地理解自定义View的实现细节。文章不仅涵盖了基础知识,还提供了实际操作建议。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 探讨如何通过编程技术实现100个并发连接,解决线程创建顺序问题,并提供高效的并发测试方案。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • 本文介绍了如何使用 Spring Boot DevTools 实现应用程序在开发过程中自动重启。这一特性显著提高了开发效率,特别是在集成开发环境(IDE)中工作时,能够提供快速的反馈循环。默认情况下,DevTools 会监控类路径上的文件变化,并根据需要触发应用重启。 ... [详细]
  • Java 中的 BigDecimal pow()方法,示例 ... [详细]
  • 深入理解Tornado模板系统
    本文详细介绍了Tornado框架中模板系统的使用方法。Tornado自带的轻量级、高效且灵活的模板语言位于tornado.template模块,支持嵌入Python代码片段,帮助开发者快速构建动态网页。 ... [详细]
  • 本文介绍如何利用动态规划算法解决经典的0-1背包问题。通过具体实例和代码实现,详细解释了在给定容量的背包中选择若干物品以最大化总价值的过程。 ... [详细]
author-avatar
岳骏哲爱237
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有