C++20は、プログラミング言語 C++ の標準規格 ISO/IEC 14882:2020 [1]の通称である[2]。C++17 の次のバージョンである。この規格は、2020年2月にプラハで開催された会議でWG21によって技術的に最終決定[3]され[4]、2020年9月4日に承認され、2020年12月に公開された。
C++20は、C++14やC++17と比べ新たな主要機能が追加されている[5]。以下は、C++20に受け入れられるか、C++20に含めることが検討されている変更の一部のリストである[6][要更新]。
新機能
C++20では多くの新機能が導入された。次のリストは完全ではない可能性がある。
言語
- コンセプト[7](簡潔な構文による)[8]。
- モジュール[9]
- 指示付き初期化子[10] (C99の機能、および一般的なG++拡張に基づく)
- ラムダのキャプチャとしての
[=, this][11]
- ラムダのテンプレートパラメータリスト[12]
- 「宇宙船演算子」
operator <=>による三方比較
- 範囲ベース
for文内における追加変数の初期化[13]
- 未評価コンテキストにおけるラムダ[14][15]
- デフォルトの構築可能で割り当て可能なステートレスラムダ[16]
- ラムダinit-captureでパック拡張を許可[17]
- テンプレートパラメータとしての文字列リテラル[18]
- 特定の状況で
typenameの必要性が除去される[19]
- 新しい標準属性
[[no_unique_address]] [20] 、[[likely]]および[[unlikely]] [21]
- 条件付き
explicit、明示的修飾子がブール式に依存できるようにする[22]
- 拡張された
constexpr:仮想関数[23]、共用体[24]、try および catch[25]、dynamic_cast および typeid[26]、std::pointer_traits[27]
- 新しい
constevalキーワードを使用した即時関数[28]
- 符号付き整数は、 2の補数を使用して表されるように定義された(符号付き整数オーバーフローは未定義の動作のままである) [29]
- 改訂された記憶モデル[30]
- 構造化バインディングのさまざまな改善(ラムダキャプチャとの相互作用、静的およびthread_localストレージ期間) [31][32]
- コルーチン [33]
- スコープ付き列挙型における
using[34]
constinitキーワード[35]
ライブラリ
- 範囲(1つの範囲の提案)[36]
- 配列の
std::make_sharedおよびstd::allocate_shared[37]
- アトミックスマートポインター(
std::atomic<shared_ptr<T>>やstd::atomic<weak_ptr<T>> )[38]
- ポインタを生ポインタに変換する
std::to_address[39]
<chrono>へのカレンダーとタイムゾーンの追加[40]
- 連続した配列へのビューを提供する
std::span(std::string_viewに類似するが、spanは参照シーケンスを変更可能である) [41]
<version>ヘッダー[42]
- オブジェクト表現の型キャストに使用される
std::bit_cast<>。memcpy()よりも冗長度が低く、コンパイラの内部を利用しやすくなっている[43]。
- 機能テストマクロ[44]
- さまざまなconstexprライブラリビット[45]
- デフォルトの初期化によるスマートポインタの作成[46]
std::map::containsメソッド[47]
非推奨の機能
- 添え字式でのカンマ演算子の使用は廃止予定である[48]
- (ほとんどの)
volatileは廃止予定である[49]
新しい(および変更された)キーワード
concept、constinit[35]、consteval、co_await、co_return、co_yield、requires(加えてexportの意味の変更)、およびchar8_tといった多くの新しいキーワード(および新規の「宇宙船演算子」operator <=>)が追加された[50]。また、C++20以降、explicitは式を取ることができるようになった[51]。volatileキーワードのほとんどの用法は廃止予定となった[49]。
キーワードに加えて、importやmoduleなど、特別な意味を持つ識別子が新しく加わった。
C++20で新しく追加された属性:[[likely]]、[[unlikely]]、および[[no_unique_address]][52]。
2017年7月(トロント)にC++20ワーキングドラフトに適用された変更は次のとおりである:[53]
- コンセプト
- 指示付き初期化子
- ラムダのキャプチャとしての
[=, this]
- ラムダのテンプレートパラメータリスト
- 配列の
std::make_sharedおよびstd::allocate_shared
2017年11月の秋の会議(アルバカーキ)でC++20ワーキングドラフトに適用された変更は次のとおりである:[54][55]
- 「宇宙船演算子」
operator <=>を使用した三方比較
- 範囲ベースの
forステートメント内の追加変数の初期化
- 未評価コンテキストにおけるラムダ
- デフォルトの構築可能で割り当て可能なステートレスラムダ
- ラムダinit-captureでパック拡張を許可する
- テンプレートパラメータとしての文字列リテラル
- アトミックスマートポインター(
std::atomic<shared_ptr<T>>やstd::atomic<weak_ptr<T>> )
- ポインタを生ポインタに変換する
std::to_address
2018年3月(ジャクソンビル)のC++20ワーキングドラフトに適用された変更は次のとおりである:[56]
- 特定の状況における
typenameの必要性の除去[19]
- 新しい標準属性
[[no_unique_address]] [20]、[[likely]]および[[unlikely]][21]
<chrono>へのカレンダーとタイムゾーンの追加[40]
- 連続した配列へのビューを提供する
std::span(std::string_viewと類似するが、spanは参照されたシーケンスを変更可能である)[41]
<version>ヘッダ[42]
2018年6月の夏の会議(Rapperswil)でC++20ワーキングドラフトに適用された変更は次のとおりである:[57]
2018年11月の秋の会議(サンディエゴ)でC++20ワーキングドラフトに適用された変更は次のとおりである:
- 範囲(1つの範囲の提案)
- コンセプトの簡潔な構文
- constexpr union、try および catch、dynamic_cast、typeid、std::pointer_traits。
- さまざまなconstexprライブラリビット[45]
- 新しい
constevalキーワードを使用した即時関数[28]
- 符号付き整数は、2の補数を使用して表されるように定義された(符号付き整数オーバーフローは未定義の動作のままである)[29]
契約機能の改善(契約条件でのアクセス制御)[59] (今後の標準に延期された機能のリストを参照)
- 改訂された記憶モデル[30]
- デフォルト初期化によるスマートポインタの作成[46]
2019年2月の冬の会議(コナ)でC++20ワーキングドラフトに適用された変更は次のとおりである:[60][61]
2019年7月の夏の会議(ケルン)でC++20ワーキングドラフトに適用された変更は次のとおりである[66][67][68]:
- 契約が削除された(今後の標準に延期された機能のリストを参照) [69]
- 添え字式でのカンマ演算子の使用は非推奨となった[48]
- constexprへの追加(自明なデフォルト初期化[70]、未評価のインラインアセンブリ[71])
- スコープ付き列挙型のusing[34]
- 宇宙船演算子へのさまざまな変更[72][73]
- DR:モジュールへの軽微な変更[74]
constinitキーワード
- コンセプトに対する変更(
-> Type return-type-requirements の削除[75])
- (ほとんどの)
volatileを非推奨とした[49]
- DR:コンストラクタに対する
[[nodiscard]]の効果[76]
- 新しい標準ライブラリのコンセプトはPascalCaseを使用しないこととなった(ほかの標準ライブラリと同様、standard_caseを使用する)[77]
- テキストのフォーマット[78][79](chronoの統合[80]、特殊なケースにおける修正[81])
- ビット操作[82]
constexpr INVOKE[83]
- 数学定数[84]
- アトミックへの一貫性の追加(
std::atomic_ref<T>[85]、std::atomic<std::shared_ptr<T>>[86])
<=>演算子を標準ライブラリに追加[87]
- 標準ライブラリのヘッダーユニット[88]
- 同期機能[89](マージ元:効率的なアトミック待機とセマフォ[90]、ラッチとバリア[91]、atomic_flagの改善[92]、C++を小さいCPUで実装できないようにしない[93] )
std::source_location[94]
- constexprコンテナ(
std::string[95]、std::vector[96])
std::stop_tokenおよびjoinされるスレッド(std::jthread)[97]
2019年11月の秋の会議(ベルファスト)でのNBコメントの解決中に適用された変更には以下を含む:[98][99][100]
- 非タイプテンプレートパラメータ(NTTP)のクラスタイプ:テンプレート引数の等価性の意味が
operator==から分離されたため、ユーザー定義のoperator==許可しないという制限がなくなった[101]。これにより、クラスタイプのNTTPの配列メンバーも許可される。
- 浮動小数点型[102]、ポインターと参照、および共用体とunionライクなクラス(無名共用体を含むクラス型)がNTTPとして許可されるようになった。
- 関数IDに末尾のrequire句も含まれるようになった(P1971)
- 制約された非テンプレート関数が削除された
<compare>がフリースタンディング実装で利用可能になった[103]
std::spanのtypedefは、標準ライブラリの他の部分と一致するようにsize_typeからindex_typeに変更された[104]
- コンセプトの名前が、ケルンでの会議の結果に従って変更された。
- 範囲に対するいくつかの修正と追加(P1456R1:移動のみのビュー[105]、P1391R4:
std::string_viewに対する範囲コンストラクタ(文字のイテレーターペアからのコンストラクタ)[106]、P1394R4:std::span<ref>に対する範囲コンストラクタ[107]、P1870R1:forwarding-range<T>が微妙すぎる[108])
std::atomic<T>の初期化が変更され、デフォルトおよびリスト初期化で動作するようになった[109]。std::latchおよびstd::barrierは、新しいメンバ関数max()を通じて実装がサポートするスレッドの最大数を報告できるようになった。
std::weak_equalityとstd::strong_equalityは使用されなくなったため削除された
<numeric>内のアルゴリズムがconstexprとなった。
- C++20の新機能または変更された機能の不足している機能テストマクロが追加されました[110]
技術仕様として公開されている機能
今後の標準に延期された機能
脚注
- ^ “ISO/IEC 14882:2020 Programming languages — C++” (2020年12月). 2023年1月27日閲覧。
- ^ “cpprefjp - C++日本語リファレンス C++20”. 2023年1月29日閲覧。
- ^ Sutter (2019年10月1日). “P1000R3: C++ IS schedule”. 2020年2月13日閲覧。
- ^ Dusíková (2019年11月6日). “N4817: 2020 Prague Meeting Invitation and Information”. 2020年2月13日閲覧。
- ^ “Why does the C++ standard ship every three years?”. 2019年7月19日閲覧。
- ^ “P0592R0: To boldly suggest an overall plan for C++20”. 2017年5月6日閲覧。
- ^ “P0606R0: Concepts Are Ready”. 2017年5月6日閲覧。
- ^ “P1141R1 - Yet another approach for constrained declarations”. 2018年11月11日閲覧。
- ^ a b “N4720: Working Draft, Extensions to C++ for Modules”. 2019年4月30日閲覧。
- ^ Tim Shen. “Designated Initialization Wording”. 2017年7月16日閲覧。
- ^ Thomas Köppe. “Allow lambda capture [=, this]”. 2017年7月16日閲覧。
- ^ “Familiar template syntax for generic lambdas”. 2017年7月16日閲覧。
- ^ “Range-based for statements with initializer”. 2019年10月30日閲覧。
- ^ “Trip Report: C++ Standards Meeting in Albuquerque, November 2017” (英語). There's Waldo!. (2017年11月20日). https://botondballo.wordpress.com/2017/11/20/trip-report-c-standards-meeting-in-albuquerque-november-2017/ 2017年12月11日閲覧。
- ^ “Wording for lambdas in unevaluated contexts”. 2017年12月11日閲覧。
- ^ “Default constructible and assignable stateless lambdas”. 2017年12月11日閲覧。
- ^ “Pack expansion in lambda init-capture”. www.open-std.org. 2017年12月11日閲覧。
- ^ “String literals as non-type template parameters”. 2017年12月11日閲覧。
- ^ a b Nina Ranns. “Down with typename!”. 2019年5月18日閲覧。
- ^ a b “Language support for empty objects”. 2019年8月4日閲覧。
- ^ a b “Proposed wording for likely and unlikely attributes (Revision 5)”. 2019年5月18日閲覧。
- ^ a b “explicit(bool)”. www.open-std.org. 2018年11月13日閲覧。
- ^ a b “Allowing Virtual Function Calls in Constant Expressions”. www.open-std.org. 2019年3月11日閲覧。
- ^ “P1330R0 - Changing the active member of a union inside constexpr”. 2019年10月14日閲覧。
- ^ “P1002R0 - Try-catch blocks in constexpr functions”. 2018年11月11日閲覧。
- ^ “P1327R0 - Allowing dynamic_cast, polymorphic typeid in Constant Expressions”. 2019年10月14日閲覧。
- ^ “P1006R1 - Constexpr in std::pointer_traits”. 2018年11月11日閲覧。
- ^ a b “P1073R2 - Immediate functions”. 2018年11月11日閲覧。
- ^ a b “P1236R0: Alternative Wording for P0907R4 Signed Integers are Two's Complement”. 2018年11月11日閲覧。
- ^ a b “P0668R4: Revising the C++ memory model”. 2018年11月11日閲覧。
- ^ a b “P1091R1: Extending structured bindings to be more like variable declarations”. www.open-std.org. 2019年2月24日閲覧。
- ^ a b “P1091R2: Extending structured bindings to be more like variable declarations”. www.open-std.org. 2019年2月24日閲覧。
- ^ a b “N4649: Working Draft, Technical Specification on C++ Extensions for Coroutines”. 2017年5月6日閲覧。
- ^ a b “P1099R5: Using Enum”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ a b “P1143R2: Adding the constinit keyword”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P0896R3”. 2018年11月11日閲覧。
- ^ “Extending make_shared to Support Arrays”. 2020年2月16日閲覧。
- ^ Meredith. “Revising atomic_shared_ptr for C++20”. JTC1/SC22/WG21 - The C++ Standards Committee - ISOCPP. ISO. 2018年12月27日閲覧。
- ^ “Utility to convert a pointer to a raw pointer”. 2020年2月12日閲覧。
- ^ a b Howard E. Hinnant. “Extending <chrono> to Calendars and Time Zones”. 2019年5月18日閲覧。
- ^ a b Neil MacIntosh. “span: bounds-safe views for sequences of objects”. 2019年5月18日閲覧。
- ^ a b Alan Talbot. “<version>”. 2019年5月18日閲覧。
- ^ a b “Bit-casting object representations”. www.open-std.org. 2018年11月10日閲覧。
- ^ a b “Integrating feature-test macros into the C++ WD”. www.open-std.org. 2018年11月10日閲覧。
- ^ a b “P1032R1 - Misc constexpr bits”. 2018年11月11日閲覧。
- ^ a b “Smart pointer creation with default initialization”. 2020年2月12日閲覧。
- ^ “std::map::contains - cppreference.com”. en.cppreference.com. 2020年5月12日閲覧。
- ^ a b “P1161R2: Deprecate uses of the comma operator in subscripting expressions”. www.open-std.org. 2019年7月20日閲覧。
- ^ a b c “P1152R4: Deprecating volatile”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “C++ keywords - cppreference.com”. en.cppreference.com. 2019年8月4日閲覧。
- ^ “explicit specifier - cppreference.com”. en.cppreference.com. 2019年8月4日閲覧。
- ^ “attribute specifier sequence(since C++11) - cppreference.com”. en.cppreference.com. 2019年8月4日閲覧。
- ^ Herb Sutter. “Trip report: Summer ISO C++ standards meeting (Toronto)”. 2017年7月16日閲覧。
- ^ Herb Sutter. “Trip report: Fall ISO C++ standards meeting (Albuquerque)”. 2017年12月4日閲覧。
- ^ Smith. “N4714 Editors' Report -- Programming Languages -- C++”. C++ standards drafts. GitHub. 2018年12月27日閲覧。
- ^ Botond Ballo. “Trip Report: C++ Standards Meeting in Jacksonville, March 2018”. 2019年5月18日閲覧。
- ^ Herb Sutter. “Trip report: Summer ISO C++ standards meeting (Rapperswil)”. 2018年11月10日閲覧。
- ^ “Support for contract based programming in C++”. www.open-std.org. 2018年11月10日閲覧。
- ^ “P1289R0 - Access control in contract conditions”. 2018年11月11日閲覧。
- ^ “r/cpp - 2019-02 Kona ISO C++ Committee Trip Report (C++20 design is complete; Modules in C++20; Coroutines in C++20; Reflection TS v1 published; work begins on a C++ Ecosystem Technical Report)” (英語). reddit. 2019年2月24日閲覧。
- ^ “Trip report: Winter ISO C++ standards meeting (Kona)” (英語). Sutter’s Mill (2019年2月23日). 2019年2月24日閲覧。
- ^ “Clang 5 Release Notes on coroutines”. 2018年8月31日閲覧。
- ^ “Clang 5 documentation on Modules”. 2017年5月6日閲覧。
- ^ “C++ Modules in VS 2015 Update 1”. 2018年8月10日閲覧。
- ^ a b “cxx-modules - GCC Wiki”. gcc.gnu.org. 2019年2月24日閲覧。
- ^ “r/cpp - 2019-07 Cologne ISO C++ Committee Trip Report — 🚀 The C++20 Eagle has Landed 🚀 (C++20 Committee Draft shipped; Contracts Moved From C++20 to a Study Group; `std::format` in C++20; C++20 Synchronization Library)” (英語). reddit. 2019年9月15日閲覧。
- ^ Botond Ballo. “Trip Report: C++ Standards Meeting in Cologne, July 2019”. 2019年8月5日閲覧。
- ^ Sutter. “Trip report: Summer ISO C++ standards meeting (Cologne)”. 2019年7月21日閲覧。
- ^ Josuttis. “P1823R0: Remove Contracts from C++20”. 2019年8月20日閲覧。
- ^ “Permitting trivial default initialization in constexpr contexts”. 2019年7月20日閲覧。
- ^ “P1668R1: Enabling Constexpr Intrinsics By Permitting Unevaluated inline-asm in Constexpr Functions”. www.open-std.org. 2019年7月20日閲覧。
- ^ “P1186R3: When do you actually use <=>?”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1630R1: Spaceship needs a tune-up”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1766R1: Mitigating minor modules maladies”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1452R2: On the non-uniform semantics of return-type-requirements”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1771R1: nodiscard for constructors”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1754R1: Rename concepts to standard_case for C++20, while we still can”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P0645R10: Text Formatting”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “std::format in C++20”. www.zverovich.net (2019年7月23日). 2019年9月15日閲覧。
- ^ “P1361R2: Integration of chrono with text formatting”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1652R1: Printf corner cases in std::format”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P0553R4: Bit operations”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1965R2: constexpr INVOKE”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P0631R8: Math Constants”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1643R1: Add wait/notify to atomic_ref<T>”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1664R0: Add wait/notify to atomic<shared_ptr<T>>”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1614R2: The Mothership has Landed - Adding <=> to the Library”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1502R1: Standard library header units for C++20”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P1135R6: The C++20 Synchronization Library”. www.open-std.org (2019年7月20日). 2019年7月20日閲覧。
- ^ “P0514R4: Efficient concurrent waiting for C++20”. 2019年7月20日閲覧。
- ^ “P0666R2: Revised Latches and Barriers for C++20”. 2019年7月20日閲覧。
- ^ “P0995R1: Improving atomic_flag”. 2019年7月20日閲覧。
- ^ “P1285R0: Don't Make C++ Unimplementable On Small CPUs”. 2019年7月20日閲覧。
- ^ “P1208R6: Adopt source_location from Library Fundamentals V3 for C++20”. 2019年8月20日閲覧。
- ^ “P0980R1: Making std::string constexpr”. 2019年8月20日閲覧。
- ^ “P1004R2: Making std::vector constexpr”. 2019年8月20日閲覧。
- ^ “P0660R10: Stop Token and Joining Thread”. 2019年8月20日閲覧。
- ^ “r/cpp - 2019-11 Belfast ISO C++ Committee Trip Report — Started Processing Feedback on the C++20 Committee Draft; ABI Review Group Formed” (英語). reddit. 2019年11月9日閲覧。
- ^ Sutter (2019年11月9日). “Trip report: Autumn ISO C++ standards meeting (Belfast)” (英語). Sutter’s Mill. 2019年11月9日閲覧。
- ^ botondballo (2019年11月15日). “Trip Report: C++ Standards Meeting in Belfast, November 2019” (英語). There's Waldo!. 2019年11月24日閲覧。
- ^ “P1907R0: Inconsistencies with non-type template parameters”. www.open-std.org (2019年10月7日). 2019年11月9日閲覧。
- ^ “P1714: NTTP are incomplete without float, double, and long double! (Revision 1)”. www.open-std.org (2019年7月19日). 2019年11月9日閲覧。
- ^ “P1855R=: Make <compare> freestanding”. www.open-std.org (2019年10月5日). 2019年11月9日閲覧。
- ^ “P1872R0: span should have size_type not index_type”. www.open-std.org (2019年9月16日). 2019年11月9日閲覧。
- ^ “P1456: Move-only views”. www.open-std.org (2019年1月25日). 2019年11月9日閲覧。
- ^ “[P1391R4 P1391: Range constructor for std::string_view]”. www.open-std.org. 2019年11月9日閲覧。
- ^ “P1394: Range constructor for std::span”. www.open-std.org (2019年8月2日). 2019年11月9日閲覧。
- ^ “P1870R1: forwarding-range<T> is too subtle”. www.open-std.org. 2019年11月9日閲覧。
- ^ “P0883: Fixing Atomic Initialization”. www.open-std.org (2018年6月5日). 2019年11月9日閲覧。
- ^ “Missing feature-test macros 2018-2019”. www.open-std.org (2019年10月6日). 2019年11月9日閲覧。
- ^ “C++ Extensions for Parallelism Version 2”. 2019年7月9日閲覧。
- ^ “Task Blocks”. 2017年7月23日閲覧。
- ^ “C++ Extensions for Networking”. 2019年7月9日閲覧。
- ^ “C++ Extensions for Reflection”. 2019年7月9日閲覧。
- ^ Sutter (2019年7月20日). “Trip report: Summer ISO C++ standards meeting (Cologne)” (英語). Sutter’s Mill. 2019年7月21日閲覧。
- ^ “Reflections on the reflection proposals - Meeting C++” (英語). meetingcpp.com. 2017年6月30日閲覧。
- ^ “Static reflection”. www.open-std.org. 2018年11月10日閲覧。
- ^ Herb Sutter. “Metaclasses”. 2017年7月23日閲覧。
- ^ “A Unified Executors Proposal for C++”. www.open-std.org. 2019年2月24日閲覧。
- ^ “N4771: Working Draft, C++ Extensions for Networking”. 2019年3月23日閲覧。
- ^ “ISO/IEC TS 19216:2018 Programming Languages -- C++ Extensions for Networking”. 2018年12月17日閲覧。
- ^ “A General Property Customization Mechanism”. www.open-std.org. 2019年2月24日閲覧。
- ^ “A Unified Futures Proposal for C++”. 2019年7月8日閲覧。
関連項目
外部リンク