基本介紹
- 中文名:C++11
- 外文名:C++11
- 標準版本:C++標準第三版
- 發布時間:2011年8月12日
- 出版時間:2011年9月
- 標準檔案號:ISO/IEC 14882:2011
基本信息
版本變更
現狀
示例
auto otherVariable = 5;//otherVariable被按照int型來編譯
auto someStrangeCallableType = boost::bind(&SomeFunction,_2,_1,someObject);
int someInt;decltype(someInt) otherIntegerVariable = 5;
for(vector<int>::const_iteratoritr=myvec.begin(); itr!=myvec.end(); ++itr)
for(auto itr = myvec.begin(); itr != myvec.end(); ++itr)
#include<vector>int main(){ const std::vector<int>v(1); auto a = v[0];//a為int類型 decltype(v[0]) b = 0;//b為const int&類型,即std::vector<int>::operator[](size_type)const的返回類型 auto c = 0;//c為int類型 auto d = c;//d為int類型 decltype(c) e;//e為int類型,c實體的類型 decltype((c)) f = e;//f為int&類型,因為(c)是左值 decltype(0) g;//g為int類型,因為0是右值 return 0;}
int my_array[5]={1, 2, 3, 4, 5};for(int& x : my_array){x *= 2;}
功能 | VS2011 | VS2013 | g++ 4.7 | Clang 3.1 |
auto關鍵字 | Yes | Yes | Yes | Yes |
decltype關鍵字 | Yes | Yes | Yes | Yes |
右值引用(Rvalue references)與移動語義(move semantics) | Yes | Yes | Yes | Yes |
Lambda表達式 | Yes | Yes | Yes | Yes |
nullptr關鍵字 | Yes | Yes | Yes | Yes |
靜態斷言(static_assert)關鍵字 | Yes | Yes | Yes | Yes |
基於範圍的循環(Range based for loop)語法 | Yes | Yes | Yes | Yes |
函式返回類型後置(Trailing return type in functions)語法 | Yes | Yes | Yes | Yes |
final關鍵字 | Yes | Yes | Yes | Yes |
override關鍵字 | Yes | Yes | Yes | Yes |
強類型枚舉(Strongly typed enums) | Yes | Yes | Yes | Yes |
前置枚舉聲明(Forward declared enums) | Yes | Yes | Yes | Yes |
外部模板(extern templates) | Yes | Yes | Yes | Yes |
模板右尖括弧嵌套(>> for nested templates) | Yes | Yes | Yes | Yes |
Local and unnamed types as template arguments | Yes | Yes | Yes | Yes |
變參宏(Variadic macros) | Yes | Yes | Yes | Yes |
新內建類型(New built-in types) | Partial(部分) | ? | Yes | Yes |
Initializer_lists容器 | No | ? | Yes | Yes |
顯式類型轉換運算符(explicit type conversion operators) | No | Yes | Yes | Yes |
內聯命名空間(Inline namespaces) | No | ? | Yes | Yes |
sizeof用在沒實例時的非靜態成員 (sizeof on non-static data members without an instance) | No | ? | Yes | Yes |
改變union成員限制(Changed restrictions on union members) | No | ? | Yes | Yes |
Raw string literals | No | Yes | Yes | Yes |
User defined literals | No | ? | Yes | Yes |
Encoding support in literals | No | ? | Yes | Yes |
Arbitrary expressions in template deduction contexts | No | ? | Yes | Yes |
默認方法(Defaulted methods) | No | Yes(有條件支持) | Yes | Yes |
刪除方法(Deleted methods) | No | Yes(有條件支持) | Yes | Yes |
非靜態成員初始化(Non-static data member initializers) | No | ? | Yes | Yes |
變參模板(Variadic templates) | No | ? | Yes | Yes |
函式模板中的默認模板參數 (Default template arguments in function templates) | No | ? | Yes | Yes |
模板別名(Template aliases) | No | ? | Yes | Yes |
前置構造函式(Forwarding constructors) | No | ? | Yes | Yes |
noexcept關鍵字 | No | ? | Yes | Yes |
constexpr關鍵字 | No | ? | Yes | Yes |
Alignment 支持 | Partial(部分) | Partial(部分) | Yes | Yes |
*this的右值引用 | No | ? | No | Yes |
C99兼容性(C99compatibility) | Partial(部分) | Partial(部分) | Partial(部分) | Partial(部分) |
執行緒本地存儲(Thread local storage) | Partial(部分) | Partial(部分) | Partial(部分) | |
構造函式繼承(Inheriting constructors) | No | ? | No | No |
Generalized attributes | No | ? | No | No |
功能支持表
C++11 Core Language Features | Visual Studio 2010 | Visual Studio 2012 | Visual Studio 2013 |
---|---|---|---|
Rvalue referencesv0.1,v1.0,v2.0,v2.1,v3.0 | v2.0 | v2.1* | v2.1* |
ref-qualifiers | No | No | No |
Non-static data member initializers | No | No | Yes |
Variadic templatesv0.9,v1.0 | No | No | Yes |
Initializer lists | No | No | Yes |
static_assert | Yes | Yes | Yes |
autov0.9,v1.0 | v1.0 | v1.0 | v1.0 |
Trailing return types | Yes | Yes | Yes |
Lambdasv0.9,v1.0,v1.1 | v1.0 | v1.1 | v1.1 |
decltypev1.0,v1.1 | v1.0 | v1.1** | v1.1 |
Right angle brackets | Yes | Yes | Yes |
Default template arguments for function templates | No | No | Yes |
Expression SFINAE | No | No | No |
Alias templates | No | No | Yes |
Extern templates | Yes | Yes | Yes |
Yes | Yes | Yes | |
Strongly typed enums | Partial | Yes | Yes |
Forward declared enums | No | Yes | Yes |
No | No | No | |
constexpr | No | No | No |
TR1 | Partial | Partial | |
Delegating constructors | No | No | Yes |
Inheriting constructors | No | No | No |
Explicit conversion operators | No | No | Yes |
char16_t/char32_t | No | No | No |
Unicode string literals | No | No | No |
Raw string literals | No | No | Yes |
Universal character names in literals | No | No | No |
User-defined literals | No | No | No |
Standard-layout and trivial types | No | Yes | Yes |
Defaulted and deleted functions | No | No | Yes* |
Extended friend declarations | Yes | Yes | Yes |
Extended sizeof | No | No | No |
Inline namespaces | No | No | No |
Unrestricted unions | No | No | No |
Local and unnamed types as template arguments | Yes | Yes | Yes |
Range-based for-loop | No | Yes | Yes |
override and finalv0.8,v0.9,v1.0 | Partial | Yes | Yes |
Minimal GC support | Yes | Yes | Yes |
noexcept | No | No | No |
並發能力
C++11 Core Language Features: Concurrency | Visual Studio 2010 | Visual Studio 2012 | Visual Studio 2013 |
---|---|---|---|
Reworded sequence points | N/A | N/A | N/A |
Atomics | No | Yes | Yes |
Strong compare and exchange | No | Yes | Yes |
Bidirectional fences | No | Yes | Yes |
Memory model | N/A | N/A | N/A |
Data-dependency ordering | No | Yes | Yes |
Data-dependency ordering: function annotation | No | No | No |
exception_ptr | Yes | Yes | Yes |
quick_exit | No | No | No |
Atomics in signal handlers | No | No | No |
Thread-local storage | Partial | Partial | Partial |
Magic statics | No | No | No |
語言功能支持
C++11 Core Language Features: C99 | Visual Studio 2010 | Visual Studio 2012 | Visual Studio 2013 |
---|---|---|---|
Partial | Partial | Partial | |
C99 preprocessor | Partial | Partial | Partial |
long long | Yes | Yes | Yes |
Extended integer types | N/A | N/A | N/A |