C++11
出自 cppreference.com
< cpp
C++11 是 C++ 的第二個主要版本,也是自 C++98 以來最重要的更新。引入了大量的變更,旨在將現有的實作標準化,並改進 C++ 程式設計師可使用的抽象。
在 2011 年 8 月 12 日最終獲得 ISO 批准之前,曾使用「C++0x」這個名稱,因為當時預期它會在 2010 年之前發佈。從 C++03 到 C++11 歷時 8 年,成為目前版本之間間隔最長的一次。從那時起,目前 C++ 固定每 3 年更新一次。
| 本節尚不完整 |
以下特性被併入了 C++11
- 來自 TR1:除了特殊函數之外的所有 TR1 內容。
- 來自 Boost:執行緒函式庫、exception_ptr、error_code 和 error_condition、疊代器改進 (begin, end, next, prev)
- 來自 C:C 風格的 Unicode 轉換函數
目錄 |
[編輯] 核心語言特性
- auto 與 decltype
- 預設 (defaulted) 與 刪除 (deleted) 函數
- final 與 override
- 尾置回傳型別 (trailing return type)
- 右值引用 (rvalue references)
- 移動建構子 (move constructors) 與 移動賦值運算子 (move assignment operators)
- 有作用域的列舉 (scoped enums)
- constexpr 與 字面量型別 (literal types)
- 列表初始化
- 委派 (delegating) 與 繼承 (inherited) 建構子
- 大括號或等號初始化器 (brace-or-equal initializers)
- nullptr
- long long
- char16_t 與 char32_t
- 型別別名 (type aliases)
- 可變參數模板 (variadic templates)
- 廣義(非顯淺)等位體 (generalized unions)
- 廣義 POD(顯淺型別 (trivial types) 與 標準佈局型別 (standard-layout types))
- Unicode 字串字面值
- 使用者定義字面量 (user-defined literals)
- 屬性 (attributes)
- Lambda 表達式 (lambda expressions)
- noexcept 說明符與 noexcept 運算子
- alignof 與 alignas
- 多執行緒記憶體模型
- 執行緒區域儲存 (thread-local storage)
- GC 介面 (在 C++23 中移除)
- 範圍 for 迴圈 (range-for)(基於 Boost 函式庫)
- static_assert(基於 Boost 函式庫)
| 本節尚不完整 |
[編輯] 函式庫特性
[編輯] 標頭檔
- <array>
- <atomic>
- <cfenv>
- <chrono>
- <cinttypes>
- <condition_variable>
- <cstdint>
- <cuchar>
- <forward_list>
- <future>
- <initializer_list>
- <mutex>
- <random>
- <ratio>
- <regex>
- <scoped_allocator>
- <system_error>
- <thread>
- <tuple>
- <typeindex>
- <type_traits>
- <unordered_map>
- <unordered_set>
[編輯] 函式庫特性
- 併發支援函式庫
-
emplace()及其在現有函式庫各處對右值引用的其他使用 - std::unique_ptr
- std::move_iterator
- std::initializer_list
- 有狀態 (stateful) 與 有作用域 (scoped) 配置器
- std::forward_list
- chrono 函式庫
- ratio 函式庫
- 新演算法
- std::all_of, std::any_of, std::none_of,
- std::find_if_not,
- std::copy_if, std::copy_n,
- std::move, std::move_backward,
- std::random_shuffle, std::shuffle,
- std::is_partitioned, std::partition_copy, std::partition_point,
- std::is_sorted, std::is_sorted_until,
- std::is_heap, std::is_heap_until,
- std::minmax, std::minmax_element,
- std::is_permutation,
- std::iota,
- std::uninitialized_copy_n
- Unicode 轉換語系層面
- std::function
- std::exception_ptr
- std::error_code 與 std::error_condition
- 疊代器 (iterator) 改進
| 本節尚不完整 |
[編輯] 缺陷報告
[編輯] 編譯器支援
[編輯] C++11 核心語言特性
| C++11 特性 |
提案論文 (Papers) |
GCC |
Clang |
MSVC |
Apple Clang |
EDG eccp |
Intel C++ |
Nvidia HPC C++ (原 PGI)* |
Nvidia nvcc |
Cray |
Embarcadero C++ Builder |
IBM Open XL C++ for AIX |
用於 z/OS 的 IBM Open XL C++ |
IBM XL C++ |
Sun/Oracle C++ |
HP aCC |
Digital Mars C++ |
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| C99 預處理器 | N1653 | 4.3 | 是 | 19.0 (2015)* (部分支援)* 19.26* |
是 | 4.1 | 11.1 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 10.1 | 5.9 | A.06.25 | 是 | |
| static_assert (FTM)* | N1720 | 4.3 | 2.9 | 16.0* | 是 | 4.1 | 11.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 | 5.13 | A.06.25 | 8.52 | |
| 右角括號 | N1757 | 4.3 | 是 | 14.0* | 是 | 4.1 | 11.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 | 5.13 | |||
| 擴展 friend 宣告 | N1791 | 4.7 | 2.9 | 16.0* | 是 | 4.1 | 11.1 (部分支援) 12.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 | 5.13 | A.06.25 | ||
long long
|
N1811 | 是 | 是 | 14.0* | 是 | 是 | 是 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 是 | 是 | 是 | 是 | |
| auto | N1984 | 4.4 | 是 | 16.0* | 是 | 3.9 | 11.0 (部分支援)* 12.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 | 5.13 | A.06.25 | ||
| 委派建構子 (FTM)* | N1986 | 4.7 | 3.0 | 18.0* | 是 | 4.7 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 | 5.13 | A.06.28 | ||
| extern template | N1987 | 3.3 | 是 | 12.0* | 是 | 3.9 | 9.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 | 5.13 | A.06.25 | ||
| constexpr (FTM)* | N2235 | 4.6 | 3.1 | 19.0 (2015)* | 是 | 4.6 | 13.0 (部分支援) 14.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 (部分支援) 13.1 |
5.13 | A.06.28 | ||
char16_t 與 char32_t (FTM)* |
N2249 | 4.4 | 2.9 | 19.0 (2015)* | 是 | 4.4 | 12.1 (部分支援)* 14.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1* | 5.13 | A.06.27 | 8.52 | |
| 編譯器對型別特徵 (type traits) 的支援。N2255* | N2255 N2984 N3142 |
4.3 (部分支援)* 4.8 (部分支援)* 5 |
3.0 | 14.0* (部分支援)* 19.0 (2015)* |
是 | 4.0 | 10.0 | 2015 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.3 | 5.13 | 6.16 | |||
| 模板別名 (FTM)* | N2258 | 4.7 | 3.0 | 18.0* | 是 | 4.2 | 12.1 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1* | 5.13 | A.06.27 | ||
| alignas | N2341 | 4.8 | 3.0 | 19.0 (2015)* | 是 | 4.8 | 15.0 | 2015 | 7.0 | 8.6 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | |||
| alignof | N2341 | 4.5 | 2.9 | 19.0 (2015)* | 是 | 4.8 | 15.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | |||
| 預設與刪除函數 | N2346 | 4.4 | 3.0 | 18.0* | 是 | 4.1 | 12.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1 | 5.13 | A.06.25 | ||
強型別 enum
|
N2347 | 4.4 | 2.9 | 16.0* (部分支援) 17.0* |
是 | 4.0 | 13.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 | 5.13 | A.06.25 | ||
| 原子操作 | N2427 | 4.4 | 3.1 | 17.0* | 是 | 是 | 13.0 | 2015 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.14 | ||||
| nullptr | N2431 | 4.6 | 2.9 | 16.0* | 是 | 4.2 | 12.1 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1 | 5.13 | A.06.27 | 8.52 | |
| 顯式轉換運算子 | N2437 | 4.5 | 3.0 | 18.0* | 是 | 4.4 | 13.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 | 5.13 | A.06.27 | ||
| 參照修飾符 (ref-qualifiers) (FTM)* | N2439 | 4.8.1 | 2.9 | 19.0 (2015)* | 是 | 4.7 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.28 | ||
| Unicode 字串字面量 (FTM)* | N2442 | 4.4 | 3.0 | 19.0 (2015)* | 是 | 4.7 | 11.0* | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 10.1* 13.1.1* |
5.7 | A.06.28 | 8.52 | |
| 原始 字串字面量 (Raw string literals) (FTM)* | N2442 | 4.5 | 是 | 18.0* | 是 | 4.7 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1, 除 AIX xlC 13.1.3 以外* | 5.13 | A.06.28 | 8.52 | |
| 行內命名空間 | N2535 | 4.4 | 2.9 | 19.0 (2015)* | 是 | 4.5 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 | 5.13 | A.06.28 | ||
| 繼承建構子 (FTM)* | N2540 | 4.8 | 3.3 | 19.0 (2015)* | 是 | 4.8 | 15.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1* | 5.13 | |||
| 尾置函數回傳型別 | N2541 | 4.4 | 2.9 | 16.0* | 是 | 4.1 | 12.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 | 5.13 | A.06.27 | ||
| 不受限的 等位體 (unions) | N2544 | 4.6 | 3.0 | 19.0 (2015)* | 是 | 4.6 | 14.0* | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.28 | ||
| 可變參數模板 (FTM)* | N2242 N2555 |
4.3 (部分支援)* 4.4 |
2.9 | 18.0* | 是 | 4.3 (部分支援)* 4.3 |
12.1 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 (部分支援)* | 5.13 | A.06.27 | ||
| 表達式 SFINAE | N2634 | 4.4 | 2.9 | 19.14* | 是 | 4.2 | 12.1 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | |||||
| 區域與未命名型別作為模板參數 | N2657 | 4.5 | 2.9 | 16.0* | 是 | 4.2 | 12.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.27 | ||
| 執行緒局部儲存 | N2659 | 4.4 (部分支援) 4.8 |
3.3* | 16.0* (部分支援) 19.0 (2015)* |
是 | 4.8 | 11.1 (部分支援) 15.0* |
2015 | 8.4 | 是 | 17.1.0 | 1.1.0 | 10.1 (部分支援)* 13.1.2 (部分支援)* |
5.9 (部分支援) | 8.52 (部分支援) | |||
| 具併發性的動態初始化與銷毀 (magic statics) (FTM)* | N2660 | 4.3 | 2.9 | 19.0 (2015)* | 是 | 是 | 11.1* | 2015 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.25 | |||
| 垃圾回收與基於可達性的洩漏偵測 | N2670 | |||||||||||||||||
| 初始化列表 (FTM)* | N2672 | 4.4 | 3.1 | 18.0* | 是 | 4.5 | 13.0 (部分支援) 14.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.28 | ||
| 非靜態資料成員初始化器 (FTM)* | N2756 | 4.7 | 3.0 | 18.0* | 是 | 4.6 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.28 | ||
屬性 (Attributes), [[noreturn]] (FTM)* |
N2761 | 4.8 | 3.3 | 19.0 (2015)* | 是 | 4.2 | 12.1 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1* | 5.13 | A.06.27 | ||
[[carries_dependency]] |
N2556 N2643 |
3.3* | 17.1.0* | |||||||||||||||
前置 (不透明) enum 宣告
|
N2764 | 4.6 | 3.1 | 17.0* | 是 | 4.5 | 11.1 (部分支援) 14.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 | 5.13 | |||
| 使用者定義字面量 (FTM)* | N2765 | 4.7 | 3.1 | 19.0 (2015)* | 是 | 4.8 | 15.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.14 | |||
| 右值引用 (Rvalue references) (FTM)* | N2118 N2844 CWG1138 |
4.3 (部分支援)* 4.5 |
2.9 | 16.0* (部分支援)* 17.0* |
是 | 4.5 | 11.1 (部分支援)* 12.0 (部分支援)* 14.0 |
2015 | 7.0* | 8.4 | 是 | 17.1.0 | 1.1.0 | 12.1 | 5.13 | A.06.25 | ||
| Lambda 表達式 (FTM)* | N2550 N2658 N2927 |
4.5 | 3.1 | 16.0* (部分支援)* 17.0* |
是 | 4.1 | 12.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.25 | ||
| 範圍 for 迴圈 (FTM)* | N2930 N3271 |
4.6 | 3.0 | 17.0* | 是 | 4.5 | 13.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.2* | 5.13 | A.06.28 | ||
| noexcept | N3050 | 4.6 | 3.0 | 19.0 (2015)* | 是 | 4.5 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1* | 5.13 | A.06.28 | ||
| 預設移動特殊成員函數 | N3053 | 4.6 | 3.0 | 19.0 (2015)* | 是 | 4.5 | 14.0 | 2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 5.13 | A.06.25 | |||
| override 與 final | N2928 N3206 N3272 |
4.7 | 2.9 | 14.0* (部分支援) 17.0* |
是 | 4.8 | 12.0 (部分支援)* 14.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 13.1.1* | 5.13 | |||
| decltype (FTM)* | N2343 N3276 |
4.3 (部分支援)* 4.8.1 |
2.9 | 16.0* (部分支援)* 17.0* |
是 | 4.2 (部分支援)* 4.8 |
11.0 (部分支援)* 12.0 |
2015 | 7.0 | 8.4 | 是 | 17.1.0 | 1.1.0 | 11.1 (部分支援)* | 5.13 | A.06.25 | 8.52 (部分支援)* | |
| C++11 特性 |
提案論文 (Papers) |
GCC |
Clang |
MSVC |
Apple Clang |
EDG eccp |
Intel C++ |
Nvidia HPC C++ (原 PGI)* |
Nvidia nvcc |
Cray |
Embarcadero C++ Builder |
IBM Open XL C++ for AIX |
用於 z/OS 的 IBM Open XL C++ |
IBM XL C++ |
Sun/Oracle C++ |
HP aCC |
Digital Mars C++ |
[編輯] C++11 函式庫特性
| C++11 特性 |
提案論文 (Papers) |
GCC libstdc++ |
Clang libc++ |
MSVC STL |
Apple Clang* |
IBM Open XL C/C++ for AIX* |
Sun/Oracle C++* |
Embarcadero C++ Builder* |
|
|---|---|---|---|---|---|---|---|---|---|
| 正規表達式函式庫 | N1429 | 4.9 | 2.8 | 是 | 是 | 17.1.0 | |||
| 型別特徵 (Type traits)。N1836* | N1836 N2240 N2244 N2255 N2342 N2984 N3142 |
4.3 (部分支援)* 4.8 (部分支援)* 5 |
3.0 | 14.0* (部分支援)* 19.0 (2015)* |
是 | 17.1.0 | 5.13 | 是 | |
容器的成員函數 cbegin, cend, crbegin, 與 crend |
N1913 LWG1192 |
4.3 (部分支援)* 4.5 |
是* | 16.0* | 是* | 17.1.0 | |||
| 垃圾回收與基於可達性的洩漏偵測 (函式庫支援) | N2670 | 6 (無操作)* |
3.4 (無操作)* |
19.0 (2015)* (無操作)* |
是 (無操作)* |
17.1.0 | |||
| 貨幣、時間與十六進位浮點數 I/O 操縱器 | N2071 N2072 |
5 | 3.8 | 19.0 (2015)* | 是 | 17.1.0 | 5.15 | ||
| 禁止 COW (寫入時複製) std::basic_string | N2668 | 5 | 是 | 是 | 是 | 17.1.0 | 是 | ||
| C++11 特性 |
提案論文 (Papers) |
GCC libstdc++ |
Clang libc++ |
MSVC STL |
Apple Clang* |
IBM Open XL C/C++ for AIX* |
Sun/Oracle C++* |
Embarcadero C++ Builder* |
* - 將游標懸停在標有星號 * 的儲存格上可查看額外的彈出說明。
DRnn - "DR" 後的數字 nn 表示該缺陷報告適用的 C++ 修訂版本,例如 DR20 → C++20。
[編輯] 外部連結
| 1. | C++11 - Wikipedia |
| 2. | 可運行的 C++11 範例 |