Namespaces
Variants

C++20

Von de.cppreference.net
< cpp

C++20 ist eine Hauptversion nach C++17 mit wichtigen Neuerungen (Konzepte, Module, Coroutinen und Bereiche) sowie weiteren Sprach- und Bibliotheksmerkmalen. Der Standard wurde im Dezember 2020 veröffentlicht.

Neue Sprachmerkmale

Neue Bibliotheksmerkmale

Neue Header

in Thread-Unterstützungsbibliothek:

Bibliotheksmerkmale

Fehlerberichte

Fehlerberichte, die in C++20 behoben wurden (158 Kern, 345 Bibliothek)

Compiler-Unterstützung

Hauptartikel: C++20-Compiler-Unterstützung

C++20-Kernsprachenmerkmale

10 16 5.1 2021.1 20.7 12.0 DR11: Array-Größenableitung bei
C++20-Merkmal

 
Papier(e)

 
GCC
Clang
MSVC
Apple Clang
EDG eccp
Intel C++
Nvidia HPC C++ (ex PGI)*
Nvidia nvcc
Cray
Erlaube 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 (teilweise)*
10 (teilweise)*
12
9 19.25* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Designierte Initialisierer  (FTM)* P0329R4 4.7 (teilweise)*
8
3.0 (teilweise)*
10
19.21* 12.0.0* 5.1 2021.1 20.7 12.0 11.0
Template-Parameter-Liste 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 Klassenschablonen-Argumentdeduktion 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* (teilweise)*
19.30*
12.0.0* (teilweise) 6.1 2023.1* 20.11 12.0 11.0
Lambdas in nicht ausgewerteten Kontexten P0315R4 9 13 (teilweise)*
14 (teilweise)*
17
19.28 (16.8)* 13.1.6* (teilweise) 6.2 2023.1 (teilweise)
2024.0
20.7 12.0
Drei-Wege-Vergleichsoperator   (FTM)* P0515R3 10 8 (teilweise)
10
19.20* 12.0.0* 5.1 2021.1 20.7 12.0 11.0
DR11: Vereinfachung des impliziten Lambda-Captures 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
Standardmäßig konstruierbare und zuweisbare zustandslose Lambdas P0624R2 9 8 19.22* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Typkonflikt bei default-Implementierten speziellen Memberfunktionen P0641R2 9 (teilweise)* 8 19.0 (2015)* (teilweise)* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Zugriffsprüfung bei Spezialisierungen P0692R1 Ja 8 (teilweise)
14
19.26* 14.0.0* 5.1 2021.1 20.7 12.0
ADL und nicht sichtbare Funktionsschablonen P0846R0 9 9 19.21* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
DR11: Festlegen, wann constexpr Funktionsdefinitionen für die Konstantenauswertung benötigt werden  (FTM)* P0859R0 5.2 (teilweise)*
9
8 19.27* (teilweise)*
19.31**
11.0.0* (teilweise) 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 noch optionaler machen P0634R3 9 16 19.29 (16.10)* 16.0.0* 5.1 2023.1 20.7 12.0
Pack-Erweiterungen in Lambda-Init-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 Regeln zum Auffinden von Structured Bindings-Anpassungspunkten P0961R1 8 8 19.20* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
DR11: Lockerung der Regeln zum Auffinden von Bereichs-for-Anpassungspunkten P0962R1 8 8 19.25* 11.0.0* 5.1 2021.1 20.7 12.0 11.0
DR17: Erlaube Structured Bindings für zugängliche Member P0969R0 8 8 19.20* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
Löschen 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 (teilweise) 19.26*(teilweise)*
19.28 (16.9)*
13.0.0* (teilweise) 6.2 2023.1 (teilweise) 21.3 12.0
Veralten des impliziten Captures von this über [=] 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* (teilweise)
19.20*
Ja 5.0 2021.1 20.7 12.0 11.0
Aggregate mit benutzerdeklarierten Konstruktoren verbieten P1008R1 9 8 19.20* 10.0.1* 5.1 2021.1 20.7 12.0 11.0
constexpr virtuelle Funktion  (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 (teilweise)
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
Unmittelbare Funktionen (consteval)  (FTM)* P1073R3 10 (teilweise)*
11
11 (teilweise)
14 (teilweise)*
17
19.28 (16.8)*
(teilweise)*

19.29 (16.10)*
11.0.3* (teilweise)
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 eingeschränkte Deklarationen P1141R2 10 10 19.26* (teilweise)
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
Wechsel des aktiven Members einer Union innerhalb 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 (teilweise)
17 (teilweise)*
19.0 (2015)* (teilweise)
19.10**
19.28 (16.8)*
10.0.1* (teilweise) 5.1 2021.1 23.3* 12.0 (nur Host-Code)
Initialisierung von Aggregaten mit runden Klammern ( FTM)* P0960R3 19.28 (16.8)* 16.0.0*
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 (teilweise) 8 (teilweise) 19.0 (2015)* (teilweise)
19.10**
19.28 (16.8)*
10.0.1* (teilweise) 2023.1 (teilweise)
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 default-Implementierte Funktionen mit unterschiedlichen Ausnahmespezifikationen P1286R2 10 9 19.28 (16.8)* 11.0.3* 5.1 2021.1 20.7 12.0 11.0
Lambda-Capture und Speicherklassenspezifizierer von Structured Bindings P1091R3
P1381R1
10 8 (teilweise)
16
19.11**
19.24**
16.0.0* 5.1 2021.1 20.7 12.0
Konvertierungen zu Arrays unbekannter Bindung 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
Veralten einiger Verwendungen von volatile 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
Kommaoperator in Indizes veralten 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-Deklaration 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 des Drei-Wege-Vergleichs für eine bestimmte 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
Klassenschablonen-Argumentdeduktion für Alias-Schablonen  (FTM)* P1814R0 10 19 19.27* 6.5 23.9 12.0
Klassenschablonen-Argumentdeduktion für Aggregate  (FTM)* P1816R0
P2082R1
10*
11*
17 19.27* 6.3 2023.1 (teilweise)*
2024.1
23.3 12.0
DR11: Implizites Move für weitere lokale Objekte und Rvalue-Referenzen P1825R0 11* 13 19.24* 13.1.6* 6.0 2021.5 20.11 12.0
Standardmäßige Vergleiche per Wert erlauben P1946R0 10 10 19.25* 12.0.0* 6.1 2021.7 20.11 12.0 11.0
Entferne 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 (teilweise)
11
18 (teilweise)* 19.26* 13.1.6* (teilweise) 6.2 2023.1 (teilweise) 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* nach bool sollte als einschränkend betrachtet werden P1957R2 10*
11*
11 19.27* 12.0.5* 6.1 12.0 11.0
 

C++20-Merkmal
 

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

C++20-Bibliotheksmerkmale

10 13 10 8 9 9
C++20-Merkmal

 
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 gepufferte Ausgabe (std::basic_osyncstream)  (FTM)* P0053R7 11 18 19.29 (16.10)*
constexpr für <algorithm> und <utility>  (FTM)* P0202R3 10 8 (teilweise)
12
19.26* 10.0.1* (teilweise)
13.0.0*
Mehr constexpr für <complex>  (FTM)* P0415R1 9 7 (teilweise)
16
19.27* 10.0.0* (teilweise)
15.0.0*
Mach std::memory_order zu einer bereichsbezogenen Enumeration P0439R0 9 9 19.25* 11.0.3*
Zeichenketten-Präfix- und Suffix-Prüfung: string(_view) ::starts_with / ends_with  (FTM)* P0457R2 9 6 19.21* 10.0.0*
Bibliotheksunterstützung für den 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*
Dienstprogramm zur Konvertierung eines Zeigers in einen Rohzeiger  (FTM)* P0653R2 8 6 19.22* Ja
Atomic 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 Zeitzone  (FTM)* P0355R7 11 (teilweise)*
13 (teilweise)*
14
7 (teilweise)
19 (teilweise)*
19.29 (16.10)* 10.0.0* (teilweise)
<version> P0754R2 9 7 19.22* 10.0.0*
Vergleichen ungeordneter Container P0809R0 Ja Ja 16.0* Ja
ConstexprIterator-Anforderungen  (FTM)*  (FTM)* P0858R0 9 12 19.11* 13.0.0*
std::basic_string::reserve() sollte nicht verkleinern P0966R1 11 8 19.25* 10.0.1*
Atomic-Vergleiche-und-Austausch 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 Kopierelision 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*
Ganzzahl-Potenz-von-2-Operationen:

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 (teilweise)* 19.21* 13.0.0* (teilweise)*
Constexpr für std::swap() und verwandte Funktionen swap P0879R0 19.26* 13.1.6*
std::type_identity  (FTM)* P0887R1 9 8 19.21* 10.0.1*
Konzepte-Bibliothek  (FTM)* P0898R3 10 13 19.23* 13.1.6*
constexpr-Vergleichsoperatoren für std::array P1023R0 19.27* 10.0.1*
und std::unwrap_ref_decaystd::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 (teilweise)
16
19.22* 10.0.1* (teilweise)
15.0.0*
Dienstprogrammfunktionen zur Implementierung der uses-allocator-Konstruktion P0591R4 9 16 19.29 (16.10)* 15.0.0*
DR17: std::variant und std::optional sollten die Trivialität von Kopieren/Verschieben propagieren P0602R4 8.3 8 19.11* 10.0.1*
DR17: Ein vernünftiger std::variant-konvertierender Konstruktor 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 One-Ranges-Vorschlag  (FTM)* P0896R4 10 13 (teilweise)
15*
19.29 (16.10)* 14.0.3*
Heterogene Suche für ungeordnete assoziative Container  (FTM)* P0919R3
P1690R1
11 12 19.23* (P0919R3)
19.25* (P1690R1)
13.0.0*
<chrono>-zero(), min()- und max()-Mitglieder 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*
Smart-Pointer-Erstellung mit Standardinitialisierung (z. B. make_unique_for_overwrite)  (FTM)* P1020R1
P1973R1
11*
12*
16 19.28 (16.9)* 15.0.0*
Verschiedene 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*
Zustandsbehaftete Allocator-Weitergabe für operator+(basic_string) konsistenter gestalten P1165R1 10 15 19.26* 14.0.3*
Einheitliches 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-Units P1502R1 11 19.29 (16.10)*
polymorphic_allocator<> als Vokabular-Typ  (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*
Benutzerfreundlichkeitsverbesserungen für std::span P1024R3 10 9*
14
19.26* 11.0.3*
DR17: std::create_directory() intuitiv gestalten P1164R1 8.3 12 19.20* 13.0.0*
std::ssize() und unsigned-Ausdehnung für std::span  (FTM)* P1227R2 10 9 19.25* 11.0.3*
Traits für (un)[]gebundene Arrays ( FTM)* P1357R1 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äts- und Zeiger-Interkonvertierbarkeits-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 für std::allocator und verwandte Dienstprogramme  (FTM)* P0784R7 10 12 19.29 (16.10)* 13.0.0*
constexpr für std::string  (FTM)* P0426R1
P1032R1
P0980R1
12 15 19.29 (16.10)*
19.30**
14.0.3*
constexpr für std::vector  (FTM)* P1004R2 12 15 19.29 (16.10)*
19.30**
14.0.3*
Eingabe-Bereichs-Adapter P1035R7 10 16 19.29 (16.10)* 15.0.0*
constexpr für std::invoke() und verwandte Dienstprogramme P1065R2 10 12 19.28 (16.8)* 13.0.0*
Atomic-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*
(teilweise)
16
19.29 (16.10)* 15.0.0*
Hinzufügen von <=> zur Standardbibliothek P1614R2 10 14*
(teilweise)
17*
(teilweise)
19
19.29 (16.10)* 13.1.6* (teilweise)
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-Merkmal
 

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

* – Bewegen Sie die Maus über eine mit dem Stern * markierte Zelle, um zusätzliche Popup-Notizen zu sehen.
DRnn – die Zahl nn nach "DR" gibt die Ziel-C++-Revision des Fehlerberichts an, z. B. DR20 → C++20.

Externe Links

1.  C++20 – Wikipedia
2.  Arbeitsbeispiele für C++20