[C++]各编译器对C++11的支持比较

各编译器对C++11的支持比较

转载请注明出处为KlayGE游戏引擎,本文的永久链接为http://www.klayge.org/?p=2154

KlayGE首次引入C++11特性之后,我顺便调研了一下个主流编译器对C++11的支持度,以便在下个版本中加入更多的C++11元素。这里还列出了在不支持的时候,可以采用的替代方案。主要参考了C++11 Features in Visual C++ 11Status of Experimental C++0x Support in GCC 4.6Status of Experimental C++0x Support in GCC 4.7Boost

C++11 Core Language Features

 VC 10VC 11GCC 4.6GCC 4.7替代方案
Rvalue referencesYesYesYesYesBoost.Move
Rvalue references for *thisNoNoNoNo 
Non-static data member initializersNoNoNoYes 
Variadic templatesNoNoYesYes 
Initializer listsNoNoYesYes 
static_assertYesYesYesYesBoost.Static Assert
autoYesYesYesYesBoost.Typeof
Trailing return typesYesYesYesYesBoost.ReturnType
LambdasYesYesYesYesBoost.Lambda
decltypeYesYesYesYesBoost.Typeof
Right angle bracketsYesYesYesYesTR1
Default template arguments for function templatesNoNoYesYes 
Expression SFINAENoNoYesYes 
Alias templatesNoNoNoYes 
Extern templatesYesYesYesYes 
nullptrYesYesYesYes自己实现的null_ptr
Strongly typed enumsNoYesYesYes#define
Forward declared enumsNoYesYesYes 
AttributesNoNoNoNo 
constexprNoNoYesYes 
AlignmentNoNoNoNo 
Delegating constructorsNoNoNoYes 
Inheriting constructorsNoNoNoNo 
Explicit conversion operatorsNoNoYesYes 
char16_t and char32_tNoNoYesYes 
Unicode string literalsNoNoYesYes 
Raw string literalsNoNoYesYes 
Universal character names in literalsNoNoYesYes 
User-defined literalsNoNoNoYes 
Standard-layout and trivial typesNoYesYesYes 
Defaulted and deleted functionsNoNoYesYes 
Extended friend declarationsYesYesNoYes 
Extended sizeofNoNoNoYes 
Inline namespacesNoNoYesYes 
Unrestricted unionsNoNoYesYes 
Local and unnamed types as template argumentsYesYesYesYes 
Range-based for-loopNoYesYesYesBoost.Foreach
override and finalNoYesNoYes#define
Minimal GC supportYesYesNoNo 
noexceptNoNoYesYes 

C++11 Core Language Features: Concurrency

 VC 10VC 11GCC 4.6GCC 4.7替代方案
Reworded sequence pointsNoNoNoNo 
AtomicsNoYesNoYesBoost.Atomic
Strong compare and exchangeNoYesNoNo 
Bidirectional fencesNoYesNoNo 
Memory modelNoNoNoNo 
Data-dependency orderingNoYesNoNo 
Data-dependency ordering: function annotationNoNoNoNo 
exception_ptrYesYesYesYesBoost.Exception
quick_exit and at_quick_exitNoNoNoNo 
Atomics in signal handlersNoNoNoNo 
Thread-local storageNoNoNoNoBoost.Thread
Magic staticsNoNoNoNo 
C++11 Core Language Features: C99
 VC 10VC 11GCC 4.6GCC 4.7替代方案
__func__NoNoYesYes__FUNCTION__
C99 preprocessorNoNoYesYes 
long longYesYesYesYes__int64
Extended integer typesNoNoNoNo 

C++11 Library

 VC 10VC 11GCC 4.6GCC 4.7替代方案
shared_ptr, weak_ptrYesYesYesYesBoost.SmartPtr
make_/allocate_shared, owner_beforeYesYesYesYesBoost.SmartPtr
unique_ptrYesYesYesYesBoost.Interprocess
Fixed-Size ArraysYesYesYesYesBoost.Arrays
Hash TablesYesYesYesYesBoost.Unordered
Singly-linked listYesYesYesYesBoost.Container
Regular ExpressionsYesYesYesYesBoost.Regex
TupleYesYesYesYesBoost.Tuple
Random Numbers & DistributionsYesYesYesYesBoost.Random
Type TraitsYesYesYesYesBoost.TypeTraits
Generalized Function PointersYesYesYesYesBoost.Function
Generalized BindersYesYesYesYesBoost.Bind
Generalized Member Function AdaptersYesYesYesYesBoost.Bind
Reference WrappersYesYesYesYesBoost.Ref
Return type calculationYesYesYesYesBoost.ReturnType
New algorithmsYesYesYesYesBoost.Algorithm
TimeNoNoYesYesBoost.Chrono

其中,斜体的Yes表示VC 11和GCC 4.7都支持,同时还有非C++11的替代方案,所以很可能在下一版本的KlayGE中使用到。从上面的表可以看出,Library的支持度相当好。即使编译器不支持,也可以很容易地用Boost替换掉。语言核心则还远不到完美,但最常用的基本都已经涵盖了。有些feature,比如foreach和auto,用Boost在库级别支持,对编译速度有很大影响。换用C++11在核心语言级别支持的话应该有较大幅度的编译性能提升。

转载于:https://www.cnblogs.com/lapsang/archive/2013/02/07/2908830.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值