文章目錄
前提
C++11,爲什麼是11呢,因爲在2011年發佈的版本。
C++11又叫做C++2.0
對於C++11,下面的筆記主要是談新東西,找一些好用的東西.觀看的視頻是侯捷的C++11視頻教程
對於各種編譯器平臺支持的C++
https://en.cppreference.com/w/cpp/compiler_support
三個常用的網站
[cppreference]https://zh.cppreference.com/
[cplusplus]http://www.cplusplus.com/
推薦的幾本書
推薦全文檢索工具
- evethring
- fiepro
推薦編輯器和工具
- cmake
- gcc/g++ linux
- minggw32/64
- qtcreater
- vscode
查看C++版本
#include <iostream>
int main()
{
std::cout<<__cplusplus;
}
C++ Statndard
- C++98 (1.0)
- C++ 03 (TR1)
- C++ 11(2.0)
- C++ 14
C++標準庫頭文件
不在使用.h,推薦使用
核心列表
- Variadic Templates
- move Semantics
- auto
- Range-base for loop
- auto
- Range-base for loop
- Initializer list
- Lambdas
C++11
C++11是第二個專業的C++版本(之前的一個版本是C++98,下一個版本是C++17)並且是自C++98版本後最重要的更新。這是一個重大版本的改變是引入了及既規範了現有的實踐,又提高了C++程序員可用的抽象。
在2011年8月12日ISO最終批准之前,使用了“C++ 0x”的名字,因爲它預計在2010之前發佈。它在C++ 03和C++ 11之間花費了8年,因此它已經成爲迄今爲止版本之間最長的間隔。從C++11後起,C++經常每3年更新一次。(C++11,C++14,C++17,C++20)
以下特徵合併爲C++ 11:
- 來自TR1:除特殊功能外的所有TR1。
- 來自Boost:The thread library, exception_ptr, error_code and error_condition,
iterator improvements (std::begin, std::end, std::next, std::prev) - From C: C-style Unicode轉換函數
核心語言特徵
- auto and decltype
- defaulted and deleted functions
- final and override
- trailing return type
- rvalue references
- move constructors/move assignment
- scoped enums
- constexpr and literal types
- list initialization
- delegating and inherited constructors
- brace-or-equal initializers
- nullptr
- long long
- char16_t and char32_t
- type aliases
- variadic templates
- generalized unions
- generalized PODs
- Unicode string literals
- user-defined literals
- attributes
- lambda expressions
- noexcept
- alignof and alignas
- multithreaded memory model
- thread-local storage
- GC interface
- range for (based on a Boost library)
- static assertions (based on a Boost library)
庫功能
頭文件
<typeindex>
<type_traits>
<chrono>
<initializer_list>
<tuple>
<scoped_allocator>
<cstdint>
<cinttypes>
<system_error>
<cuchar>
<array>
<forward_list>
<unordered_set>
<unordered_map>
<random>
<ratio>
<cfenv>
<regex>
<atomic>
<thread>
<mutex>
<future>
<condition_variable>
庫功能
- atomic operations library
- emplace() and other use of rvalue references throughout all parts of the existing library
- std::initializer_list
- stateful and scoped allocators
- forward_list
- chrono library
- ratio library
- new algorithms
- Unicode conversion facets
- The thread library
- exception_ptr
- error_code and error_condition
- iterator improvements:
- std::begin
- std::end
- std::next
- std::prev
- Unicode conversion functions
編輯器支持情況
https://zh.cppreference.com/w/cpp/compiler_support#C.2B.2B11_features
C++11 核心語言功能特性
C++11功能特性 | 提案 | GCC | Clang | MSVC | AppleClang | EDGeccp | IntelC++ | IBMXLC++ | Sun/OracleC++ | EmbarcaderoC++Builder | Cray | PortlandGroup(PGI) | Nvidianvcc | HPaCC | DigitalMarsC++ |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
C99預處理器 | N1653 | 4.3 | 是 | 19.0*(部分)19.26 | 是 | 4.1 | 11.1 | 10.1 | 5.9 | 是 | 8.4 | 2015 | 7 | A.06.25 | 是 |
static_assert | N1720 | 4.3 | 2.9 | 16.0* | 是 | 4.1 | 11 | 11.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | 8.52 |
右角括號 | N1757 | 4.3 | 是 | 14.0* | 是 | 4.1 | 11 | 12.1 | 5.13 | 是 | 8.4 | 2015 | 7 | ||
擴展的friend聲明 | N1791 | 4.7 | 2.9 | 16.0*(部分)18.0* | 是 | 4.1 | 11.1(部分)12.0 | 11.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | |
longlong | N1811 | 是 | 是 | 14.0* | 是 | 是 | 是 | 是 | 是 | 是 | 8.4 | 2015 | 7 | 是 | 是 |
類型特徵的編譯器支持 | N1836 | 4.3 | 3 | 14.0* | 是 | 4 | 10 | 13.1.3 | 5.13 | 是 | 8.4 | 2015 | 6.16 | ||
auto | N1984 | 4.4 | 是 | 16.0* | 是 | 3.9 | 11.0(v0.9)12.0 | 11.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | |
委託構造函數 | N1986 | 4.7 | 3 | 18.0* | 是 | 4.7 | 14 | 11.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
externtemplate | N1987 | 3.3 | 是 | 12.0* | 是 | 3.9 | 9 | 11.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | |
constexpr | N2235 | 4.6 | 3.1 | 19.0* | 是 | 4.6 | 13.0(部分)14.0 | 12.1(部分)13.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
模板別名 | N2258 | 4.7 | 3 | 18.0* | 是 | 4.2 | 12.1 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | |
char16_t與char32_t | N2249 | 4.4 | 2.9 | 19.0* | 是 | 4.4 | 12.1*14.0 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | 8.52 |
alignas | N2341 | 4.8 | 3 | 19.0* | 是 | 4.8 | 15 | 13.1.2* | 5.13 | 是 | 8.6 | 2015 | 7 | ||
alignof | N2341 | 4.5 | 2.9 | 19.0* | 是 | 4.8 | 15 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | ||
默認化與被刪除的函數 | N2346 | 4.4 | 3 | 18.0* | 是 | 4.1 | 12 | 13.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | |
強類型enum | N2347 | 4.4 | 2.9 | 17.0* | 是 | 4 | 13 | 12.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | |
原子操作 | N2427 | 4.4 | 3.1 | 17.0* | 是 | Yes | 13 | 13.1.2* | 5.14 | 是 | 8.4 | 2015 | |||
nullptr | N2431 | 4.6 | 2.9 | 16.0* | 是 | 4.2 | 12.1 | 13.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | 8.52 |
顯式轉換運算符 | N2437 | 4.5 | 3 | 18.0* | 是 | 4.4 | 13 | 12.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | |
引用限定符 | N2439 | 4.8.1 | 2.9 | 19.0* | 是 | 4.7 | 14 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
Unicode字符串字面量 | N2442 | 4.4 | 3 | 19.0* | 是 | 4.7 | 11.0* | 10.113.1.1 | 5.7 | 是 | 8.4 | 2015 | 7 | A.06.28 | 8.52 |
未處理的字符串字面量 | N2442 | 4.5 | 是 | 18.0* | 是 | 4.7 | 14 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | 8.52 |
內聯命名空間 | N2535 | 4.4 | 2.9 | 19.0* | 是 | 4.5 | 14 | 11.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
繼承構造函數 | N2540 | 4.8 | 3.3 | 19.0* | 是 | 4.8 | 15 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | ||
尾隨的函數返回類型 | N2541 | 4.4 | 2.9 | 16.0* | 是 | 4.1 | 12.1 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | ||
無限制的聯合體 | N2544 | 4.6 | 3 | 19.0* | 是 | 4.6 | 14.0* | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
變參數模板 | N2242N2555 | 4.3(N2242)4.4 | 2.9 | 18.0* | 是 | 4.3(N2242)4.3 | 12.1 | 11.1(N2242) | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | |
表達式SFINAE | N2634 | 4.4 | 2.9 | 19.14* | 是 | 4.2 | 12.1 | 是 | 8.4 | 2015 | 7 | ||||
局部與無名類型作爲模板形參 | N2657 | 4.5 | 2.9 | 16.0* | 是 | 4.2 | 12 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | |
線程局部存儲 | N2659 | 4.4(部分)4.8 | 3.3* | 16.0*(部分)19.0* | 是 | 4.8 | 11.1(部分)15.0* | 10.1(部分)13.1.2(部分) | 5.9(部分) | 是 | 8.4 | 2015 | 8.52(部分) | ||
帶併發的動態初始化與析構(魔法靜態變量) | N2660 | 4.3 | 2.9 | 19.0* | 是 | Yes | 11.1* | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | A.06.25 | ||
垃圾收集與基於可達性的泄漏檢測 | N2670 | ||||||||||||||
初始化器列表 | N2672 | 4.4 | 3.1 | 18.0* | 是 | 4.5 | 13.0(部分)14.0 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
非靜態數據成員初始化器 | N2756 | 4.7 | 3 | 18.0* | 是 | 4.6 | 14 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
屬性 | N2761 | 4.8 | 3.3 | 19.0* | 是 | 4.2 | 12.1 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.27 | |
前置enum聲明 | N2764 | 4.6 | 3.1 | 17.0* | 是 | 4.5 | 11.1(部分)14.0 | 12.1 | 5.13 | 是 | 8.4 | 2015 | 7 | ||
用戶定義的字面量 | N2765 | 4.7 | 3.1 | 19.0* | 是 | 4.8 | 15 | 13.1.2* | 5.14 | 是 | 8.4 | 2015 | 7 | ||
右值引用 | N2118N2844CWG1138 | 4.3(N2118)4.5 | 2.9 | 16.0*(N2844)17.0* | 是 | 4.5 | 11.1(N2118)12.0(N2844)14.0 | 12.1 | 5.13 | 是 | 8.4 | 2015 | 7.0* | A.06.25 | |
Lambda表達式 | N2550N2658N2927 | 4.5 | 3.1 | 16.0*(N2658)17.0* | 是 | 4.1 | 12 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | |
範圍for循環 | N2930 | 4.6 | 3 | 17.0* | 是 | 4.5 | 13 | 13.1.2* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
noexcept | N3050 | 4.6 | 3 | 19.0* | 是 | 4.5 | 14 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.28 | |
默認化的移動特殊成員函數 | N3053 | 4.6 | 3 | 19.0* | 是 | 4.5 | 14 | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | ||
override與final | N2928N3206N3272 | 4.7 | 2.9 | 14.0*(部分)17.0* | 是 | 4.8 | 12.0(N2928)14.0 | 13.1.1* | 5.13 | 是 | 8.4 | 2015 | 7 | ||
decltype | N2343N3276 | 4.3(N2343)4.8.1 | 2.9 | 16.0* | 是 | 4.2(N2343)4.8 | 11.0(N2343)12.0 | 11.1(N2343) | 5.13 | 是 | 8.4 | 2015 | 7 | A.06.25 | 8.52(N2343) |
C++11功能特性 | 提案 | GCC | Clang | MSVC | AppleClang | EDGeccp | IntelC++ | IBMXLC++ | Sun/OracleC++ | EmbarcaderoC++Builder | Cray | PortlandGroup(PGI) | Nvidianvcc | HPaCC | DigitalMarsC++ |
C++11 庫功能特性
C++11功能特性 | 提案 | GCClibstdc++ | Clanglibc++ | AppleClang | MSVC標準庫 | Sun/OracleC++標準庫 | EmbarcaderoC++Builder標準庫 | CrayC++標準庫 |
---|---|---|---|---|---|---|---|---|
類型特徵 | N1836 | 4.3 | 3 | 是 | 14.0* | 5.13 | 是 | 8.4 |
垃圾收集與基於可達性的泄漏檢測(庫支持) | N2670 | 6(無操作) | 3.4(無操作) | 是(無操作) | 19.0*(無操作) | |||
金額、時間及十六進制浮點I/O操縱符 | N2071N2072 | 5 | 3.8 | 是 | 19.0* | 5.15 | ||
C++11功能特性 | 提案 | GCClibstdc++ | Clanglibc++ | AppleClang | MSVC標準庫 | Sun/OracleC++標準庫 | EmbarcaderoC++Builder標準庫 | CrayC++標準庫 |