Namensräume
Varianten
Aktionen

C++20

Von cppreference.com
< cpp

C++20 ist eine Hauptversion nach C++17 und bietet wichtige Features (Konzepte, Module, Coroutinen und Bereiche) sowie weitere Sprach- und Bibliotheksfeatures. Der Standard wurde im Dezember 2020 veröffentlicht.

Inhalt

[bearbeiten] Neue Sprachfeatures

[bearbeiten] Neue Bibliotheksfeatures

[bearbeiten] Neue Header

in der Thread-Support-Bibliothek

[bearbeiten] Bibliotheksfeatures

[bearbeiten] Defect Reports

In C++20 behobene Defect Reports (158 Core, 345 Bibliothek)

[bearbeiten] Compiler-Unterstützung

Hauptartikel: C++20 Compiler-Unterstützung

[bearbeiten] C++20 Sprach-Kernfeatures

C++20 Feature

 
Papier(e)

 
GCC
Clang
MSVC
Apple Clang
EDG eccp
Intel C++
Nvidia HPC C++ (ehem. PGI)*
Nvidia nvcc
Cray
Erlaubt Lambda-Capture [=, this] P0409R2 8 6 19.22* 10.0.0* 5.1 2021.1 20.7 12.0 11.0
__VA_OPT__ P0306R4
P1042R1
8 (partiell)*
10 (partiell)*
12
9 19.25* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Bezeichner-Initialisierer  (FTM)* P0329R4 4.7 (partiell)*
8
3.0 (partiell)*
10
19.21* 12.0.0* 5.1 2021.1 20.7 12.0 11.0
Template-Parameterliste für generische Lambdas  (FTM)* P0428R2 8 9 19.22* 11.0.0* 5.1 2021.1 20.7 12.0 11.0
Standard-Member-Initialisierer für Bitfelder P0683R1 8 6 19.25* 10.0.0* 5.1 2021.1 20.7 12.0 11.0
Initialisierungslistenkonstruktoren bei Class-Template-Argument-Deduktion P0702R1 8 6 19.14* Ja 5.0 2021.1 20.7 12.0 11.0
const&-qualifizierte Zeiger auf Member P0704R1 8 6 19.0 (2015)* 10.0.0* 5.1 2021.1 20.7 12.0 11.0
Konzepte  (FTM)* P0734R0 5*
10
10 19.23* (partiell)*
19.30*
12.0.0* (partiell) 6.1 2023.1* 20.11 12.0 11.0
Lambdas in nicht ausgewerteten Kontexten P0315R4 9 13 (partiell)*
14 (partiell)*
17
19.28 (16.8)* 13.1.6* (partiell) 6.2 2023.1 (partiell)
2024.0
20.7 12.0
Drei-Wege-Vergleichsoperator  (FTM)* P0515R3 10 8 (partiell)
10
19.20* 12.0.0* 5.1 2021.1 20.7 12.0 11.0
DR11: Vereinfachte implizite Lambda-Capture P0588R1 8 19.24* 5.1 2021.1 20.7 12.0
Init-Anweisungen für Bereichsbasierte for-Schleifen P0614R1 9 8 19.25* 11.0.0* 6.0 2021.7 20.11 12.0 11.0
Standardkonstruierbare und zuweisbare zustandslose Lambdas P0624R2 9 8 19.22* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Typ-Mismatch von standardmäßig initialisierten speziellen Memberfunktionen P0641R2 9 (partiell)* 8 19.0 (2015)* (partiell)* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Zugriffsprüfung bei Spezialisierungen P0692R1 Ja 8 (partiell)
14
19.26* 14.0.0* 5.1 2021.1 20.7 12.0
ADL und nicht sichtbare Funktionstemplates P0846R0 9 9 19.21* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
DR11: Spezifikation, wann constexpr Funktionsdefinitionen für konstante Auswertung benötigt werden  (FTM)* P0859R0 5.2 (partiell)*
9
8 19.27* (partiell)*
19.31**
11.0.0* (partiell) 12.0 11.0
Attribute [[likely]] und [[unlikely]] P0479R5 9 12 19.26* 13.0.0* 5.1 2021.7 20.7 12.0
typename optionaler machen P0634R3 9 16 19.29 (16.10)* 16.0.0* 5.1 2023.1 20.7 12.0
Pack-Erweiterungen in Lambda-Captures  (FTM)* P0780R2 9 9 19.22* 11.0.3* 6.1 2021.7 20.11 12.0 11.0
Attribut [[no_unique_address]] P0840R2 9 9 19.28 (16.9)** 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Bedingt triviale spezielle Memberfunktionen  (FTM)* P0848R3 10 16 19.28 (16.8)* 6.1 2021.7 20.11 12.0
DR17: Lockerung der Anpassungspunkt-Findungsregeln für strukturierte Bindungen P0961R1 8 8 19.20* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
DR11: Lockerung der Anpassungspunkt-Findungsregeln für Bereichsbasierte for-Schleifen P0962R1 8 8 19.25* 11.0.0* 5.1 2021.1 20.7 12.0 11.0
DR17: Strukturierte Bindungen zu zugänglichen Membern erlauben P0969R0 8 8 19.20* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Zerstörender operator delete  (FTM)* P0722R3 9 6 19.27* 10.0.0* 6.1 2023.1 20.11 12.0 11.0
Klassentypen in Nicht-Typ-Template-Parametern P0732R2 9 12 (partiell) 19.26* (partiell)*
19.28 (16.9)*
13.0.0* (partiell) 6.2 2023.1 (partiell) 21.3 12.0
Implizites Capturing von this über [=] als veraltet markiert P0806R2 9 7 19.22* 10.0.1* 5.1 20.7 12.0 11.0
explicit(bool)  (FTM)* P0892R2 9 9 19.24* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Integration von Feature-Test-Makros P0941R2 5 3.4 19.15* (partiell)
19.20*
Ja 5.0 2021.1 20.7 12.0 11.0
Aggregate mit benutzerdefinierten Konstruktoren verbieten P1008R1 9 8 19.20* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
constexpr virtuelle Funktionen  (FTM)* P1064R0 9 9 19.28 (16.9)* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Konsistenzverbesserungen für Vergleiche P1120R0 10 8 (partiell)
10
19.22* 12.0.0* 5.1 2023.1 20.7 12.0 11.0
char8_t  (FTM)* P0482R6 9 7* 19.22* 10.0.0* 5.1 2021.1 20.7 12.0 11.0
std::is_constant_evaluated()  (FTM)* P0595R2 9 9 19.25* 11.0.3* 5.1 19.1 21.1 12.0 11.0
constexpr try-catch-Blöcke P1002R1 9 8 19.25* 10.0.1* 5.1 2023.1 20.7 12.0 11.0
Sofortfunktionen (consteval)  (FTM)* P1073R3 10 (partiell)*
11
11 (partiell)
14 (partiell)*
17
19.28 (16.8)*
(teilweise)*

19.29 (16.10)*
11.0.3* (partiell)
15.0.0*
5.1 2021.1 20.7 12.0
Verschachtelte Inline-Namespaces P1094R2 9 8 19.27* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Ein weiterer Ansatz für beschränkte Deklarationen P1141R2 10 10 19.26* (partiell)
19.28 (16.9)*
12.0.5* 6.1 2023.1 20.11 12.0 11.0
Vorzeichenbehaftete Ganzzahlen sind Zweierkomplement P1236R1 9 9 Ja 11.0.3* N/A 2023.1* ja* 12.0 11.0
dynamic_cast und polymorphes typeid in konstanten Ausdrücken P1327R1 10 9 19.28 (16.9)* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Änderung des aktiven Members eines Unions innerhalb von constexpr  (FTM)* P1330R0 9 9 19.10* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Coroutinen  (FTM)*  (FTM)* P0912R5
LWG3393
10 8 (partiell)
17 (partiell)*
19.0 (2015)* (partiell)
19.10**
19.28 (16.8)*
10.0.1* (partiell) 5.1 2021.1 23.3* 12.0 (nur Host-Code)
Klammer-Initialisierung von Aggregaten  (FTM)* P0960R3 10 16 19.28 (16.8)* 16.0.0* 5.1 2021.1 20.7 12.0
DR11: Array-Größenableitung in new-Ausdrücken P1009R2 11 9 19.27* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Module  (FTM)* P1103R3 11 (partiell) 8 (partiell) 19.0 (2015)* (partiell)
19.10**
19.28 (16.8)*
10.0.1* (partiell) 2023.1 (partiell)
Stärkere Unicode-Anforderungen P1041R4
P1139R2
10 Ja 19.0 (2015)**
19.26**
Ja N/A 2023.1* Ja 12.0 11.0
<=> != == P1185R2 10 10 19.22* 12.0.0* 5.1 2021.1 20.7 12.0 11.0
DR11: Explizit standardmäßige Funktionen mit unterschiedlichen Ausnahme-Spezifikationen P1286R2 10 9 19.28 (16.8)* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Lambda-Capture und Speicherklassen-Spezifizierer von strukturierten Bindungen P1091R3
P1381R1
10 8 (partiell)
16
19.11**
19.24**
16.0.0* 5.1 2021.1 20.7 12.0
Konvertierungen zu Arrays unbekannter Größe erlauben P0388R4 10 14 19.27* 14.0.0* 6.0 2021.5 20.11 12.0
constexpr Containeroperationen  (FTM)* P0784R7 10 10 19.28 (16.9)* 12.0.0* 6.0 2021.5 20.11 12.0 11.0
Einige Verwendungen von volatile als veraltet markiert P1152R4 10 10 19.27* 12.0.0* 6.0 2021.5 20.11 12.0 11.0
constinit  (FTM)* P1143R2 10 10 19.29 (16.10)* 12.0.0* 6.1 2021.7 20.11 12.0 11.0
Komma-Operator in Indizes als veraltet markiert P1161R3 10 9 19.25* 11.0.3* 6.0 2021.7 20.11 12.0 11.0
[[nodiscard]] mit Nachricht P1301R4 10 9 19.25* 11.0.3* 6.0 2021.5 20.11 12.0 11.0
Triviale Standardinitialisierung in constexpr Funktionen P1331R2 10 10 19.27* 12.0.0* 6.1 2021.7 20.11 12.0 11.0
Nicht ausgewertete asm-Deklarationen in constexpr Funktionen P1668R1 10 10 19.28 (16.9)* 12.0.0* 6.1 2021.7 20.11 12.0 11.0
using enum  (FTM)* P1099R5 11 13 19.24* 13.1.6* 6.3 2023.1 22.5 12.0
Synthetisieren von Drei-Wege-Vergleichen für eine angegebene Vergleichskategorie P1186R3 11 10 19.24* 12.0.0* 6.0 2021.5 20.11 12.0 11.0
DR17: [[nodiscard]] für Konstruktoren P1771R1 10 9 19.24* 11.0.3* 6.0 2021.5 20.11 12.0 11.0
Class-Template-Argument-Deduktion für Alias-Templates  (FTM)* P1814R0 10 19 19.27* 6.5 23.9 12.0
Class-Template-Argument-Deduktion für Aggregate  (FTM)* P1816R0
P2082R1
10*
11*
17 19.27* 6.3 2023.1 (partiell)*
2024.1
23.3 12.0
DR11: Impliziter Move für mehr lokale Objekte und Rvalue-Referenzen P1825R0 11* 13 19.24* 13.1.6* 6.0 2021.5 20.11 12.0
Vergleiche per Wert erlauben P1946R0 10 10 19.25* 12.0.0* 6.1 2021.7 20.11 12.0 11.0
Entfernen von std::weak_equality und std::strong_equality P1959R0 10 10 19.25* 12.0.0* 6.1 2021.7 20.11 12.0 11.0
Inkonsistenzen bei Nicht-Typ-Template-Parametern  (FTM)* P1907R1 10 (partiell)
11
18 (partiell)* 19.26* 13.1.6* (partiell) 6.2 2023.1 (partiell) 21.3 12.0
DR98: Pseudo-Destruktoren beenden Objektlebensdauern P0593R6 11 11 Ja 12.0.5* N/A 2023.1* Ja 12.0 11.0
DR11: Konvertierung von T* zu bool sollte als Verengung betrachtet werden P1957R2 10*
11*
11 19.27* 12.0.5* 6.1 12.0 11.0
 

C++20 Feature
 

Papier(e)
GCC
Clang
MSVC
Apple Clang
EDG eccp
Intel C++
Nvidia HPC C++ (ehem. PGI)*
Nvidia nvcc
Cray

[bearbeiten] C++20 Bibliotheksfeatures

C++20 Feature

 
Papier(e)

 
GCC libstdc++
Clang libc++
MSVC STL
Apple Clang*
std::endian  (FTM)* P0463R1 8 7 19.22* 10.0.0*
Erweiterung von std::make_shared() zur Unterstützung von Arrays  (FTM)* P0674R1 12 15 19.27* 14.0.3*
Gleitkomma-Atomics  (FTM)* P0020R6 10 18 19.22* 16.0.0*
Synchronisierte Puffer (std::basic_osyncstream)  (FTM)* P0053R7 11 18 19.29 (16.10)*
constexpr für <algorithm> und <utility>  (FTM)* P0202R3 10 8 (partiell)
12
19.26* 10.0.1* (partiell)
13.0.0*
Mehr constexpr für <complex>  (FTM)* P0415R1 9 7 (teilweise)
16
19.27* 10.0.0* (teilweise)
15.0.0*
Machen Sie std::memory_order zu einer ámbito-gebundenen Enumeration P0439R0 9 9 19.25* 11.0.3*
String Präfix- und Suffixprüfung: string(_view) ::starts_with / ends_with  (FTM)* P0457R2 9 6 19.21* 10.0.0*
Bibliotheksunterstützung für operator<=> <compare>  (FTM)* P0768R1 10 7 (teilweise)
12 (teilweise)*
17
19.20* (teilweise)
19.28 (16.9)*
13.0.0*
std::remove_cvref  (FTM)* P0550R2 9 6 19.20* 10.0.0*
[[nodiscard]] in der Standardbibliothek P0600R1 9 7 (teilweise)
16
19.13* (teilweise)
19.22*
10.0.0* (teilweise)
15.0.0*
Verwendung von std::move in numerischen Algorithmen P0616R0 9 12 19.23* 13.0.0*
Hilfsfunktion zur Konvertierung eines Zeigers in einen rohen Zeiger  (FTM)* P0653R2 8 6 19.22* Ja
Atomare std::shared_ptr und std::weak_ptr  (FTM)* P0718R2 12 19.27*
std::span  (FTM)* P0122R7 10 7 19.26* 10.0.0*
Kalender und Zeitzonen  (FTM)* P0355R7 11 (teilweise)*
13 (partiell)*
14
7 (teilweise)
19 (teilweise)*
19.29 (16.10)* 10.0.0* (teilweise)
<version> P0754R2 9 7 19.22* 10.0.0*
Vergleich von Unordered-Containern P0809R0 Ja Ja 16.0* Ja
ConstexprIterator-Anforderungen  (FTM)*  (FTM)* P0858R0 9 12 19.11* 13.0.0*
std::basic_string::reserve() sollte nicht schrumpfen P0966R1 11 8 19.25* 10.0.1*
Atomares Vergleichen und Austauschen mit Padding-Bits P0528R3 13 19.28 (16.8)*
std::atomic_ref  (FTM)* P0019R8 10 19 19.28 (16.8)*
contains()-Memberfunktion von assoziativen Containern, z.B. std::map::contains() P0458R2 9 13 19.21* 13.1.6*
DR11: Garantierte Kopier-Elision für stückweise Konstruktion P0475R1 9 Ja 19.29 (16.10)* Ja
std::bit_cast()  (FTM)* P0476R2 11 14 19.27* 14.0.3*
Ganzzahlige Operationen mit Zweierpotenzen

std::bit_ceil(), std::bit_floor(), std::bit_width(), std::has_single_bit()  (FTM)*

P0556R3
P1956R1
9*
10*
9*
12*
19.25**
19.27**
19.28 (16.8)*
11.0.3**
13.0.0**
Verbesserung des Rückgabewerts von erase-ähnlichen Algorithmen  (FTM)* P0646R1 9 10 19.21* 12.0.0*
std::destroying_delete_t  (FTM)* P0722R3 9 9 19.27* 11.0.3*
std::is_convertible  (FTM)* P0758R1 9 9 19.23* 11.0.3*
Hinzufügen von std::shift_left/right zu <algorithm>  (FTM)* P0769R2 10 12 19.21* 13.0.0*
Constexpr für std::swap() und swap-bezogene Funktionen P0879R0 10 13 19.26* 13.1.6*
std::type_identity  (FTM)* P0887R1 9 8 19.21* 10.0.1*
Concepts-Bibliothek  (FTM)* P0898R3 10 13 19.23* 13.1.6*
constexpr Vergleichsoperatoren für std::array P1023R0 10 8 19.27* 10.0.1*
std::unwrap_ref_decay und std::unwrap_reference  (FTM)* P0318R1 9 8 19.21* 10.0.1*
std::bind_front()  (FTM)* P0356R5 9 13 19.25* 13.1.6*
std::reference_wrapper für unvollständige Typen P0357R3 9 8 19.26* 10.0.1*
Korrektur von operator>>(basic_istream&, CharT*) P0487R1 11 8 19.23* 10.0.1*
Bibliotheksunterstützung für char8_t  (FTM)* P0482R6 9 8 (partiell)
16
19.22* 10.0.1* (partiell)
15.0.0*
Hilfsfunktionen zur Implementierung von uses-allocator-Konstruktion P0591R4 9 16 19.29 (16.10)* 15.0.0*
DR17: std::variant und std::optional sollten Kopier-/Verschiebungs-Trivialität propagieren P0602R4 8.3 8 19.11* 10.0.1*
DR17: Ein sinnvoller konvertierender Konstruktor für std::variant P0608R3 10 9 19.29 (16.10)**
19.42**
11.0.3*
std::functions move-Konstruktor sollte noexcept sein P0771R1 7.2 6 19.22* Ja
Der Ein Ranges Vorschlag  (FTM)* P0896R4 10 13 (teilweise)
15*
19.29 (16.10)* 14.0.3*
Heterogene Suche für unordered assoziative Container  (FTM)* P0919R3
P1690R1
11 12 19.23* (P0919R3)
19.25* (P1690R1)
13.0.0*
<chrono> zero(), min() und max() sollten noexcept sein P0972R0 9 8 19.14* 10.0.1*
constexpr in std::pointer_traits  (FTM)* P1006R1 9 8 19.26* 10.0.1*
std::assume_aligned()  (FTM)* P1007R3 9*
11
15 19.28 (16.9)* 14.0.3*
Erstellung von Smart Pointern mit Standardinitialisierung (z.B. make_unique_for_overwrite)  (FTM)* P1020R1
P1973R1
11*
12*
16 19.28 (16.9)* 15.0.0*
Diverse constexpr Bits  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)* P1032R1 10 13 19.28 (16.8)* 13.1.6*
Entfernen von Vergleichsoperatoren von std::span P1085R2 10 8 19.26* 10.0.1*
Konsistente Zustandsorientierte Alloziator-Propagierung für operator+(basic_string) P1165R1 10 15 19.26* 14.0.3*
Konsistentes Container-Löschen, z.B. std::erase(std::vector), oder std::erase_if(std::map)  (FTM)* P1209R0
P1115R3
9*
10*
8*
11*
19.25**
19.27**
10.0.1**
12.0.5**
Standardbibliotheks-Header-Einheiten P1502R1 11 19.29 (16.10)*
polymorphic_allocator<> als Vokabulartyp  (FTM)* P0339R6 9 16 19.28 (16.9)* 15.0.0*
std::execution::unseq  (FTM)* P1001R2 9 17 19.28 (16.8)*
std::lerp() und std::midpoint()  (FTM)* P0811R3 9 9 19.23* (teilweise)
19.28 (16.8)*
11.0.3*
Usability-Verbesserungen für std::span P1024R3 10 9*
14
19.26* 11.0.3*
DR17: Machen Sie std::create_directory() intuitiv P1164R1 8.3 12 19.20* 13.0.0*
std::ssize() und vorzeichenlose Ausdehnung für std::span  (FTM)* P1227R2 10 9 19.25* 11.0.3*
Traits für (un)begrenzte Arrays  (FTM)* P1357R1 9 9 19.25* 11.0.3*
std::to_array()  (FTM)* P0325R4 10 10 19.25* 12.0.0*
Effizienter Zugriff auf den Puffer von std::basic_stringbuf P0408R7 11 17 19.29 (16.10)* 15.0.0*
Layout-Kompatibilität und Zeiger-Interkonvertibilität-Traits  (FTM)*  (FTM)* P0466R5 12 19.29 (16.10)**
Bit-Operationen: std::

rotl(), rotr(), countl_zero(), countl_one(), countr_zero(), countr_one(), popcount()  (FTM)*

P0553R4 9 9 19.25**
19.28 (16.8)*
11.0.3*
Mathematische Konstanten  (FTM)* P0631R8 10 11 19.25* 12.0.5*
Textformatierung  (FTM)* P0645R10 13 14**
17
19.29 (16.10)* 15.0.0*
std::stop_token und std::jthread  (FTM)* P0660R10 10 17
(teilweise)*

20*
19.28 (16.9)*
constexpr std::allocator und verwandte Hilfsfunktionen  (FTM)* P0784R7 10 12 19.29 (16.10)* 13.0.0*
constexpr std::string  (FTM)* P0426R1
P1032R1
P0980R1
12 15 19.29 (16.10)*
19.30**
14.0.3*
constexpr std::vector  (FTM)* P1004R2 12 15 19.29 (16.10)*
19.30**
14.0.3*
Input-Range-Adaptoren P1035R7 10 16 19.29 (16.10)* 15.0.0*
constexpr std::invoke() und verwandte Hilfsfunktionen P1065R2 10 12 19.28 (16.8)* 13.0.0*
Atomares Warten und Benachrichtigen, std::counting_semaphore, std::latch und std::barrier  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)*  (FTM)* P1135R6 11 11 19.28 (16.9)* 13.1.6*
std::source_location  (FTM)* P1208R6 11 15*
(partiell)
16
19.29 (16.10)* 15.0.0*
Hinzufügen von <=> zur Standardbibliothek P1614R2 10 14*
(partiell)
17*
(partiell)
19
19.29 (16.10)* 13.1.6* (partiell)
constexpr Standardkonstruktor von std::atomic und std::atomic_flag  (FTM)* P0883R2 10 13 19.26* 13.1.6*
constexpr für numerische Algorithmen  (FTM)* P1645R1 10 12 19.26* 13.0.0*
Sichere Ganzzahlvergleiche  (FTM)* P0586R2 10 13 19.27* 13.1.6*
 

C++20 Feature
 

Papier(e)
GCC libstdc++
Clang libc++
MSVC STL
Apple Clang*

* - Bewegen Sie den Mauszeiger über eine Zelle, die mit dem Stern markiert ist *, um zusätzliche Pop-up-Hinweise zu sehen.
DRnn - die Nummer nn nach "DR" bezeichnet die Ziel-C++-Revision, auf die der Defect Report angewendet wird, z. B. DR20 → C++20.

[bearbeiten] Externe Links

1.  C++20 - Wikipedia
2.  Funktionierende C++20 Beispiele