メインコンテンツへスキップ
見出し画像

C++20

    WIP

    1. 主要な言語機能 (Language Features)


    【コア言語の4大機能】

    • コンセプト (Concepts) : `concept`, `requires` 節、制約付きテンプレート

    • コルーチン (Coroutines) : `co_await`, `co_yield`, `co_return`

    • モジュール (Modules) : `module`, `import`, `export`

    • 3方比較演算子 (Spaceship Operator) : `<=>`, デフォルト比較 (`= default`)

    【constexpr / コンパイル時評価の拡張】

    • constexpr 仮想関数 (Virtual functions in constexpr)

    • constexpr 動的メモリ確保 (constexpr new / delete, std::allocator)

    • constexpr try-catch ブロック (実行されないパスでの許可)

    • constexpr dynamic_cast / typeid

    • consteval (即時関数: Immediate Functions)

    • constinit (定数初期化の強制)

    • std::is_constant_evaluated() のサポート

    【テンプレート・ラムダ】

    • テンプレート構文付きラムダ式 : `[]<typename T>(T x) { ... }`

    • ラムダ式の *this のコピーキャプチャ (`[=, this]`)、暗黙 ⁠this⁠ の非推奨化

    • 評価されない文脈 (decltype等) でのステートレスラムダの使用

    • デフォルトコンストラクト/代入可能なステートレスラムダ

    • クラス型 (浮動小数点やリテラルクラス) の非型テンプレートパラメータ (NTTP)

    【構文・属性・その他】

    • レンジベース for ループでの初期化子 : `for (init; decl : range)`

    • 指名初期化子 (Designated Initializers) : `Point p = {.x = 10, .y = 20};`

    • 条件付き explicit : `explicit(bool-expr)`

    • [[nodiscard]] の理由付き構文 : `[[nodiscard("reason")]]`

    • [[likely]], [[unlikely]] 属性

    • [[no_unique_address]] 属性

    • using enum 宣言 (スコープ付き列挙型の名前空間導入)

    • char8_t 型 (UTF-8 用文字型)

    • 2の補数表現の規定 (符号付き整数の内部表現を規格として保証)

    • 条件演算子 (?:) の共通型決定ルールの改善

    • ネストされたインライン名前空間 : `namespace A::inline B { ... }`

    • auto による関数パラメータ宣言 (省略構文による関数テンプレート)

    2. 新規追加された標準ヘッダ (New Standard Headers)


    <concepts> - 概念・制約
    <coroutine> - コルーチン基盤
    <ranges> - Ranges ライブラリ
    <compare> - 3方比較・順序付け型
    <span> - 連続したメモリ領域の非所有参照
    <format> - 高速・型安全なテキストフォーマット
    <syncstream> - スレッドセーフな出力ストリーム
    <latch> - 同期プリミティブ (ラッチ)
    <barrier> - 同期プリミティブ (バリア)
    <semaphore> - 同期プリミティブ (セマフォ)
    <stop_token> - 協調的スレッド停止トークン
    <numbers> - 数学定数
    <bit> - ビット操作
    <version> - ライブラリ機能テストマクロ
    ⁠<source_location> - ファイル名・行番号・関数名を取得する(マクロ ⁠__LINE__⁠ や ⁠__FILE__⁠ の型安全な代替)

    3. 標準ライブラリの新機能・クラス・関数 (std::*)


    【Ranges (<ranges>)】

    • std::ranges 名前空間内のアルゴリズム全般 (イテレータペア不要の直接操作)

    • 主要ビュー (std::ranges::views::*):

      • all, filter, transform, take, take_while, drop, drop_while

      • join, split, lazy_split, common, reverse, elements, keys, values, iota

    • アダプタ合成 (パイプライン演算子 `|`)

    • カスタマイゼーションポイントオブジェクト (CPO):

      • std::ranges::begin, end, cbegin, cend, rbegin, rend, crbegin, crend

      • std::ranges::size, empty, data, cdata

    【フォーマット (<format>)】

    • std::format

    • std::format_to, std::format_to_n, std::formatted_size

    • std::formatter (ユーザー定義型向け拡張)

    • std::format_error

    【ユーティリティ・ポインタ・配列】

    • std::span (連続メモリのスライス参照)

    • std::make_shared / std::allocate_shared (配列型のサポート)

    • std::to_address (ポインタライクなオブジェクトから生ポインタを取得)

    • std::assume_aligned (アライメント前提の最適化指示)

    • std::identity (恒等関数オブジェクト)

    • std::bind_front (引数順束縛)

    【数学・ビット操作 (<bit>, <numbers>, <numeric>)】

    • std::bit_cast (型安全なビット再解釈)

    • ビット操作 (<bit>):

      • std::has_single_bit, std::bit_ceil, std::bit_floor, std::bit_width

      • std::rotl, std::rotr, std::countl_zero, std::countl_one

      • std::countr_zero, std::countr_one, std::popcount

      • std::endian (バイトオーダー判別)

    • 数学定数 (std::numbers::*):

      • e, log2e, log10e, pi, inv_pi, inv_sqrtpi, ln2, ln10, sqrt2, sqrt3, inv_sqrt3, phi, egamma

    • 数値演算 (<numeric>, <cmath>):

      • std::midpoint (オーバーフローしない中間値)

      • std::lerp (線形補間)

      • std::hypot (3次元対応: x, y, z)

      • std::is_eq, std::is_neq, std::is_lt, std::is_lteq, std::is_gt, std::is_gteq (比較)

    【文字列・文字・正規表現】

    • std::u8string (char8_t 対応文字列型), std::u8string_view

    • std::string::starts_with, std::string_view::starts_with

    • std::string::ends_with, std::string_view::ends_with

    • std::string::contains, std::string_view::contains (※containsはC++23正式採択分もあるが、一部view向け基盤導入)

    【コンテナ・コレクション】

    • 統一 erase / erase_if (フリー関数):

      • std::erase, std::erase_if (vector, deque, list, forward_list, string, map, set, 等)

    • 連想コンテナのルックアップ改善:

      • set / map 等の contains() メンバ関数

    • 異種ルックアップ (Heterogeneous lookup) の順序なし連想コンテナ対応 (find, count, equal_range)

    • std::vector, std::string 等の constexpr 対応拡張

    【並行処理・同期】

    • std::jthread (自動合流・協調停止可能なスレッド)

    • std::stop_token, std::stop_source, std::stop_callback

    • 同期プリミティブ:

      • std::latch

      • std::barrier

      • std::counting_semaphore, std::binary_semaphore

    • std::osyncstream (アトミックストリーム出力)

    • std::atomic<std::shared_ptr<T>>, std::atomic<std::weak_ptr<T>>

    • std::atomic::wait, std::atomic::notify_one, std::atomic::notify_all

    • std::atomic_ref (非アトミック変数へのアトミック参照インターフェース)

    • std::atomic_flag::test

    【コルーチンサポート (<coroutine>)】

    • std::coroutine_handle

    • std::coroutine_traits

    • std::noop_coroutine, std::noop_coroutine_handle

    • std::suspend_always, std::suspend_never

    【日付・時刻拡張 (<chrono>)】

    • タイムゾーンサポート (std::chrono::time_zone, std::chrono::zoned_time, std::chrono::tzdb)

    • カレンダー機能:

      • std::chrono::year, month, day

      • std::chrono::year_month_day, year_month_weekday 等

      • 日付リテラル演算子 (`using namespace std::chrono_literals; 2020y/March/1d`)

    • クロック追加:

      • std::chrono::utc_clock, tai_clock, gps_clock, file_clock

    【型特性・コンセプト (<concepts>, <type_traits>)】

    • 標準コンセプト:

      • same_as, derived_from, convertible_to, common_reference_with, common_with

      • integral, signed_integral, unsigned_integral, floating_point

      • assignable_from, swappable, destructible, constructible_from, default_initializable

      • movable, copyable, semiregular, regular

      • invocable, regular_invocable, predicate, relation, strict_weak_order

    • 型特性:

      • std::type_identity, std::type_identity_t

      • std::remove_cvref, std::remove_cvref_t

      • std::is_bounded_array, std::is_unbounded_array

      • std::unwrap_reference, std::unwrap_ref_decay


    参照:

    #C #cpp #cpp20 #programming #tutorial#modern#study #STL #std #lib


     

    遊月

     
     
    うつ回復期✨社会恐怖症。 SESなエンジニア (元ゲームPG) 日々学習、プログラミング、アニメゲーム、ドール、天然石が好き。 日記を中心に様々な情報をお届け。生成AIで遊んでます。 🗒️'20/6/8~

    あなたへのおすすめ