探索c++0x: 0.开始

33 篇文章 0 订阅
来源: http://www.cppblog.com/thesys/articles/116983.html

c++0x是下一代c++标准,原计划于2010前推出,所以命名为c++0x(比如c++09),现在已经2010年了,都还没有最终定稿,因此我们只能无奈地认为这0x代表的是16进制了,也暗合c/c++中0x代表16进制前缀的习惯,不过如果2015年还没搞定的话,就不知道可以怎么解释了。

c++0x应该说对现行c++标准的改变很大,增加了很多新特性,十分令人期待,之前我也花了不少时间来学习和了解。最近vc10和gcc4.5都release了,而这两个重要的c++编译器都部分支持了c++0x标准,因此给了我们更好的尝试和探索的机会,接下来我计划对c++0x标准进行一系列更多的学习和探索,看看我们能用新特性来干什么,以及它能给我们的工作带来多少改进。

这里先简单罗列一下c++0x标准的新特性,以及vc和gcc对它们的支持,以便接下来做逐一的学习和探索。 
下面的表格来自http://gcc.gnu.org/projects/cxx0x.html,在原始版本的基础上,我做了一点点修改,把VC的支持给标注出来。

Language FeatureProposalAvailable in GCC and VC
Rvalue referencesN2118GCC4.3, VC10
    Rvalue references for *thisN2439No
Initialization of class objects by rvaluesN1610GCC4.4, VC10
Non-static data member initializersN2756No
Variadic templatesN2242GCC4.3
    Extending variadic template template parametersN2555GCC4.4
Initializer listsN2672GCC4.4
Static assertionsN1720GCC4.3,VC10
auto-typed variablesN1984GCC4.4,VC10
    Multi-declarator autoN1737GCC4.4,VC10
    Removal of auto as a storage-class specifierN2546GCC4.4,VC10
    New function declarator syntaxN2541GCC4.4,VC10
New wording for C++0x lambdasN2927GCC4.5,VC10
Declared type of an expressionN2343GCC4.3,VC10
Right angle bracketsN1757GCC4.3,VC9
Default template arguments for function templatesDR226GCC4.3
Solving the SFINAE problem for expressionsDR339GCC4.4
Template aliasesN2258No
Extern templatesN1987GCC4.3
Null pointer constantN2431GCC4.6,VC10
Strongly-typed enumsN2347GCC4.4
Forward declarations for enumsN2764 No
Generalized attributesN2761No
Generalized constant expressionsN2235No
Alignment supportN2341No
Delegating constructorsN1986GCC patch
Inheriting constructorsN2540No
Explicit conversion operatorsN2437GCC4.5
New character typesN2249GCC4.4
Unicode string literalsN2442GCC4.5
Raw string literalsN2442GCC4.5
Universal character name literalsN2170GCC4.5
Extensible literalsN2765No
Standard Layout TypesN2342GCC4.5
Defaulted and deleted functionsN2346GCC4.4
Extended friend declarationsN1791No
Extending sizeofN2253GCC4.4
Inline namespacesN2535GCC4.4
Unrestricted unionsN2544No
Local and unnamed types as template argumentsN2657GCC4.5
Range-based forN2930No
Explicit virtual overridesN2928No
Minimal support for garbage collection and reachability-based leak detectionN2670No
Allowing move constructors to throw [noexcept]N3050No
Defining move special member functionsN3053No
Concepts [no longer part of C++0x]N2773Rejected
Concurrency
Sequence pointsN2239No
Atomic operationsN2427GCC4.4
Strong Compare and ExchangeN2748No
Bidirectional FencesN2752No
Memory modelN2429No
Data-dependency ordering: atomics and memory modelN2664No
Propagating exceptionsN2179GCC4.4
Abandoning a process and at_quick_exitN2440No
Allow atomics use in signal handlersN2547No
Thread-local storageN2659No
Dynamic initialization and destruction with concurrencyN2660No
C99 Features in C++0x
__func__ predefined identifierN2340GCC4.3
C99 preprocessorN1653GCC4.3,VC9
long longN1811GCC4.3,VC9
Extended integral typesN1988No

从表中可以看出,C++0x对现有标准进行了大量的改进,有望提高C++的市场占有率,而目前GCC对C++0x标准的支持从特性数量上明显要好于VC10。

  • 改进中最引人注目的是现代化特性,包括垃圾收集的引入,并行计算的支持,lambda表达式等,总算是让c++这门古典的语言有了一些现代编程语言的先进特性,可谓老树发新芽。
  • 很多改进是用来降低使用门槛,简化代码的,例如auto, initializer list, none-static data member initializers等,让C++这们号称最复杂的语言更容易入门和使用。
  • 还有一些用来简化模板定义的改进,例如 Variadic templates, Right angle brecket等,以往那些丑陋重复的模板定义将来或许能变得美观简洁些,特别是boost那些write only的代码。
  • 当然还有改进性能的,例如rvalue reference的引入,解决了C++中臭名昭著的临时对象的性能损失。
  • 不过其实也有不少遗憾,concepts最终还是被否决了,而反射这么重要的设施也没有被纳入,就算纳入一个编译期静态反射也好啊。

在后续的博客中我将使用VC10和GCC4.5 开始探索C++0x的新特性,为了方便起见,我使用的GCC是MinGW GCC4.5,并使用MinGW GDB7.1进行调试。需要注意的是,由于标准还没有最终定案,将来搞不好还会改,我们得出的结论将来或许会失效。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值