diff --git a/lang/cpp17/structured_bindings.md b/lang/cpp17/structured_bindings.md index 671c87b267..9d725be6ae 100644 --- a/lang/cpp17/structured_bindings.md +++ b/lang/cpp17/structured_bindings.md @@ -331,6 +331,7 @@ auto { w, {x, y}, z } = f(); // このような、tuple内にあるpairを同時 ## 関連項目 - [C++20 friend指定された関数内から構造化束縛を使用して非公開メンバ変数にアクセスすることを許可](/lang/cpp20/allow_structured_bindings_to_accessible_members.md) - [C++20 構造化束縛がカスタマイゼーションポイントを見つけるルールを緩和](/lang/cpp20/relaxing_the_structured_bindings_customization_point_finding_rules.md) +- [C++20 構造化束縛を拡張して通常の変数宣言のように使用できるようにする](/lang/cpp20/extending_structured_bindings_to_be_more_like_variable_declarations.md) - [C++20 構造化束縛した変数の参照キャプチャを許可](/lang/cpp20/reference_capture_of_structured_bindings.md) diff --git a/lang/cpp20.md b/lang/cpp20.md index e6b578efd5..8616143d66 100644 --- a/lang/cpp20.md +++ b/lang/cpp20.md @@ -113,7 +113,7 @@ C++20とは、2020年中に改訂され、ISO/IEC 14882:2020で標準規格化 | [ジェネリックラムダのテンプレート構文](cpp20/familiar_template_syntax_for_generic_lambdas.md) | ジェネリックラムダでテンプレートパラメータを定義できるようにする | | [ラムダ式のキャプチャとして`[=, this]`を許可する](cpp20/allow_lambda_capture_equal_this.md) | デフォルトコピーキャプチャと`this`ポインタのコピーキャプチャを両方指定できるようにする | | [`[=]`による`this`の暗黙のキャプチャを非推奨化](cpp20/deprecate_implicit_capture_of_this_via_defcopy.md) | コピーのデフォルトキャプチャでは、`this`ポインタをキャプチャされなくする | -| [暗黙のラムダキャプチャを簡略化](cpp20/simplifying_implicit_lambda_capture.md.nolink) | | +| [暗黙のラムダキャプチャを簡略化](cpp20/simplifying_implicit_lambda_capture.md) | | | [状態を持たないラムダ式を、デフォルト構築可能、代入可能とする](cpp20/default_constructible_and_assignable_stateless_lambdas.md) | キャプチャしていないラムダ式をデフォルト構築・代入可能にする | | [評価されない文脈でのラムダ式](cpp20/wording_for_lambdas_in_unevaluated_contexts.md) | 評価されない文脈でもラムダ式を書くことができるようにする | | [ラムダ式の初期化キャプチャでのパック展開を許可](cpp20/allow_pack_expansion_in_lambda_init_capture.md) | `[...args = std::move(args)]`のようなキャプチャを許可 | diff --git a/lang/cpp20/reference_capture_of_structured_bindings.md b/lang/cpp20/reference_capture_of_structured_bindings.md index d34d04dae6..25230502c5 100644 --- a/lang/cpp20/reference_capture_of_structured_bindings.md +++ b/lang/cpp20/reference_capture_of_structured_bindings.md @@ -31,6 +31,7 @@ int main() { ## 関連項目 - [C++17 構造化束縛](/lang/cpp17/structured_bindings.md) +- [C++20 構造化束縛を拡張して通常の変数宣言のように使用できるようにする](extending_structured_bindings_to_be_more_like_variable_declarations.md) ## 参照 diff --git a/lang/cpp20/simplifying_implicit_lambda_capture.md b/lang/cpp20/simplifying_implicit_lambda_capture.md new file mode 100644 index 0000000000..573ab11e03 --- /dev/null +++ b/lang/cpp20/simplifying_implicit_lambda_capture.md @@ -0,0 +1,33 @@ +# 暗黙のラムダキャプチャを簡略化 +* cpp20[meta cpp] + +## 概要 +ここでは、ラムダ式での暗黙のキャプチャについて、以下のN個の問題を解決する: + +1. ラムダ式内での`decltype((x))`の使用 +2. ラムダ式での構造化束縛のキャプチャ + +ラムダ式でコピーキャプチャした変数を、評価されない文脈のみで使用した場合に、その変数はクロージャオブジェクトのメンバ変数になることを仮定していた。この変更ではその仮定をやめ、式の型のみを規定するようになった。 + +```cpp +void f() { + float x, &r = x; + [=] { + decltype(x) y1; // y1はfloat型をもつ + decltype((x)) y2 = y1; // y2はconst float&型をもつ。ラムダ式がmutableではなくxが左辺値であるため + decltype(r) r1 = y1; // r1はfloat&型をもつ + decltype((r)) r2 = y2; // r2はconst float&型をもつ + }; +} +``` + +構造化束縛で導入された名前はラムダ式でキャプチャできない、と明記された。しかしその後、「[構造化束縛を拡張して通常の変数宣言のように使用できるようにする](extending_structured_bindings_to_be_more_like_variable_declarations.md)」の仕様でそれが可能となったため、この仕様変更は打ち消された。 + + +## 関連項目 +- [C++17 構造化束縛](/lang/cpp17/structured_bindings.md) +- [C++20 構造化束縛を拡張して通常の変数宣言のように使用できるようにする](extending_structured_bindings_to_be_more_like_variable_declarations.md) + +## 参照 +- [P0588R1 Simplifying implicit lambda capture](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html) +