Skip to content

Commit 8ba9fba

Browse files
committed
C++23 : 「ラムダ式に対する属性」を追加 (close #1042)
1 parent 33a231f commit 8ba9fba

File tree

7 files changed

+56
-3
lines changed

7 files changed

+56
-3
lines changed

implementation-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
| P2647R1: [`constexpr`関数内での`static constexpr`変数を許可](/lang/cpp23/permitting_static_constexpr_variables_in_constexpr_functions.md.nolink) | 13 | - | 16 | 2023.2 | - |
274274
| P2564R3: [`constexpr`関数内で`consteval`関数を呼び出せない問題を緩和](/lang/cpp23/consteval_needs_to_propagate_up.md.nolink) | | - | 17 | - | 2024.0 |
275275
| P1102R2: [ラムダ式で`()`を省略できる条件を緩和](/lang/cpp23/down_with_lambda_parens.md) | 修飾や戻り値型をともなってもパラメータリストが空であれば`()`を省略できる | 11 | 13 | 2022.2 | - |
276-
| P2173R1: [ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md.nolink) | ラムダ式のいくつかの箇所に属性を記述できるようにする | 9 | 13 | 2022.2 | - |
276+
| P2173R1: [ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md) | ラムダ式のいくつかの箇所に属性を記述できるようにする | 9 | 13 | 2022.2 | - |
277277
| P1774R8: [コード内容の仮定をコンパイラに伝えるassume属性](/lang/cpp23/portable_assumptions.md) | 最適化のために、コードの仮定をコンパイラに伝える属性を標準化する | 13 | - | - | - |
278278
| P2316R2: [文字リテラルエンコーディングを一貫させる](/lang/cpp23/consistent_character_literal_encoding.md.nolink) | プリプロセッサの条件式での文字リテラルの扱いをC++式と同様にする | yes | yes | 2022.2 | 2022 |
279279
| P2334R1: [`elif`/`elifdef`/`elifndef`のサポートを追加](/lang/cpp23/add_support_for_preprocessing_directives_elifdef_and_elifndef.md.nolink) | `#if`/`#ifdef`/`#ifndef`に対応する複数条件命令のサポートを追加する | 12 | 13 | 2022.2 | - |

lang/cpp11/attributes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ C++11で採用されたもの以外で検討された以下の機能は、属性
160160
- [C++20 `[[no_unique_address]]`属性](/lang/cpp20/language_support_for_empty_objects.md)
161161
- [C++20 `[[likely]]`, `[[unlikely]]`属性](/lang/cpp20/likely_and_unlikely_attributes.md)
162162
- [C++20 属性の名前空間を予約](/lang/cpp20/reserving_attribute_namespaces_for_future_use.md)
163+
- [C++23 ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md)
163164
164165
165166
## 参照

lang/cpp11/lambda_expressions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ for_each(array, array + 4, <&>(double d) ( sum += factor ∗ d ));
531531
- [C++20 ラムダ式のキャプチャとして`[=, this]`を許可する](/lang/cpp20/allow_lambda_capture_equal_this.md)
532532
- [C++20 ジェネリックラムダのテンプレート構文](/lang/cpp20/familiar_template_syntax_for_generic_lambdas.md)
533533
- [C++23 ラムダ式で()を省略できる条件を緩和](/lang/cpp23/down_with_lambda_parens.md)
534-
- [C++23 ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md.nolink)
534+
- [C++23 ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md)
535535

536536

537537
## 参照

lang/cpp14/deprecated_attr.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ prog.cc:45:3: warning: 'class_templ<int>' is deprecated: don't use class_templ<i
123123

124124
## 関連項目
125125
- [C++11 属性構文](/lang/cpp11/attributes.md)
126+
- [C++23 ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md)
126127

127128

128129
## 参照

lang/cpp17/nodiscard.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ nodiscard.cpp:11:3: warning: ignoring return value of function declared with 'no
5353
- [C++20 `[[nodiscard]]`をコンストラクタのオーバーロードごとに付加できるようにする](/lang/cpp20/nodiscard_for_constructors.md)
5454
- C++17対応のコンパイラでも使用できる可能性がある
5555
- [C++20 `[[nodiscard]]`属性に理由となる文字列を付加できるようにする](/lang/cpp20/nodiscard_should_have_a_reason.md)
56+
- [C++23 ラムダ式に対する属性](/lang/cpp23/attributes_on_lambda_expressions.md)
5657

5758

5859
## 参照

lang/cpp23.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ C++23とは、2023年中に改訂される予定の、C++バージョンの通
8181
| 言語機能 | 説明 |
8282
|----------|------|
8383
| [ラムダ式で`()`を省略できる条件を緩和](cpp23/down_with_lambda_parens.md) | 修飾や戻り値型をともなってもパラメータリストが空であれば`()`を省略できる |
84-
| [ラムダ式に対する属性](cpp23/attributes_on_lambda_expressions.md.nolink) | ラムダ式のいくつかの箇所に属性を記述できるようにする |
84+
| [ラムダ式に対する属性](cpp23/attributes_on_lambda_expressions.md) | ラムダ式のいくつかの箇所に属性を記述できるようにする |
8585

8686

8787
### 属性
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# ラムダ式に対する属性
2+
* cpp23[meta cpp]
3+
4+
## 概要
5+
C++23では、ラムダ式のいくつかの箇所に属性を指定できる。
6+
7+
- ラムダ式の関数呼び出し演算子自体に対する属性
8+
- キャプチャ指定のうしろ
9+
- テンプレートのラムダ式の場合は、テンプレートパラメータリストに続くrequires定義のうしろ
10+
- C++23時点でここに指定できる属性は以下
11+
- [`[[noreturn]]`](/lang/cpp11/attributes.md)
12+
- [`[[nodiscard]]`](/lang/cpp17/nodiscard.md)
13+
- [`[[deprecated]]`](/lang/cpp14/deprecated_attr.md)
14+
- ラムダ式の修飾もしくは戻り値型に対する属性
15+
- パラメータリスト、`constexpr` / `mutable``noexcept`のうしろ (このあとに後置戻り値型、requiresが続く)
16+
- C++23時点でここに指定できる標準属性なし
17+
18+
19+
##
20+
```cpp example
21+
#include <stdexcept>
22+
#include <concepts>
23+
24+
int main()
25+
{
26+
auto f1 = [] [[noreturn]] { throw std::runtime_error("error"); };
27+
auto f2 = [] [[nodiscard]] { return true; };
28+
auto f3 = [] [[deprecated]] { return false; };
29+
30+
auto f4 = [] <class T>
31+
requires std::copy_constructible<T>
32+
[[nodiscard]]
33+
(T value) {
34+
return value;
35+
};
36+
}
37+
```
38+
* std::copy_constructible[link /reference/concepts/copy_constructible.md]
39+
40+
### 出力
41+
```
42+
```
43+
44+
## 関連項目
45+
- [C++11 ラムダ式](/lang/cpp11/lambda_expressions.md)
46+
- [C++11 属性構文](/lang/cpp11/attributes.md)
47+
48+
49+
## 参照
50+
- [P2173R1 Attributes on Lambda-Expressions](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2173r1.pdf)

0 commit comments

Comments
 (0)