热门标签 | 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.

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


推荐阅读
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 本文介绍了设计师伊振华受邀参与沈阳市智慧城市运行管理中心项目的整体设计,并以数字赋能和创新驱动高质量发展的理念,建设了集成、智慧、高效的一体化城市综合管理平台,促进了城市的数字化转型。该中心被称为当代城市的智能心脏,为沈阳市的智慧城市建设做出了重要贡献。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • Go Cobra命令行工具入门教程
    本文介绍了Go语言实现的命令行工具Cobra的基本概念、安装方法和入门实践。Cobra被广泛应用于各种项目中,如Kubernetes、Hugo和Github CLI等。通过使用Cobra,我们可以快速创建命令行工具,适用于写测试脚本和各种服务的Admin CLI。文章还通过一个简单的demo演示了Cobra的使用方法。 ... [详细]
  • 本文讨论了在手机移动端如何使用HTML5和JavaScript实现视频上传并压缩视频质量,或者降低手机摄像头拍摄质量的问题。作者指出HTML5和JavaScript无法直接压缩视频,只能通过将视频传送到服务器端由后端进行压缩。对于控制相机拍摄质量,只有使用JAVA编写Android客户端才能实现压缩。此外,作者还解释了在交作业时使用zip格式压缩包导致CSS文件和图片音乐丢失的原因,并提供了解决方法。最后,作者还介绍了一个用于处理图片的类,可以实现图片剪裁处理和生成缩略图的功能。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文介绍了深入浅出Linux设备驱动编程的重要性,以及两种加载和删除Linux内核模块的方法。通过一个内核模块的例子,展示了模块的编译和加载过程,并讨论了模块对内核大小的控制。深入理解Linux设备驱动编程对于开发者来说非常重要。 ... [详细]
  • 本文介绍了如何使用Express App提供静态文件,同时提到了一些不需要使用的文件,如package.json和/.ssh/known_hosts,并解释了为什么app.get('*')无法捕获所有请求以及为什么app.use(express.static(__dirname))可能会提供不需要的文件。 ... [详细]
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社区 版权所有