C++ラムダ変遷
C++11
lambda-expression:
lambda-introducer lambda-declarator{opt} compound-statement
lambda-introducer:
[ lambda-capture{opt} ]
lambda-capture:
capture-default
capture-list
capture-default , capture-list
capture-default:
&
=
capture-list:
capture ...{opt}
capture-list , capture ...{opt}
capture:
identifier
& identifier
this
lambda-declarator:
( parameter-declaration-clause ) mutable{opt}
exception-specification{opt} attribute-specifier-seq{opt} trailing-return-type{opt}
Default arguments shall not be specified in the parameter-declaration-clause of a lambda-declarator.
C++14
lambda-expression:
lambda-introducer lambda-declarator{opt} compound-statement
lambda-introducer:
[ lambda-capture{opt} ]
lambda-capture:
capture-default
capture-list
capture-default , capture-list
capture-default:
&
=
capture-list:
capture ...{opt}
capture-list , capture ...{opt}
capture:
simple-capture
init-capture
simple-capture:
identifier
& identifier
this
init-capture:
identifier initializer
& identifier initializer
lambda-declarator:
( parameter-declaration-clause ) mutable{opt}
exception-specification{opt} attribute-specifier-seq{opt} trailing-return-type{opt}
C++17
lambda-expression:
lambda-introducer lambda-declarator{opt} compound-statement
lambda-introducer:
[ lambda-capture{opt} ]
lambda-declarator:
( parameter-declaration-clause ) decl-specifier-seq{opt}
noexcept-specifier{opt} attribute-specifier-seq{opt} trailing-return-type{opt}
In the decl-specifier-seq of the lambda-declarator, each decl-specifier shall either be
mutable
orconstexpr
.
C++17 [expr.prim.lambda.capture]
lambda-capture:
capture-default
capture-list
capture-default , capture-list
capture-default:
&
=
capture-list:
capture ...{opt}
capture-list , capture ...{opt}
capture:
simple-capture
init-capture
simple-capture:
identifier
& identifier
this
* this
init-capture:
identifier initializer
& identifier initializer
C++20
lambda-expression:
lambda-introducer lambda-declarator{opt} compound-statement
lambda-introducer < template-parameter-list > requires-clause{opt} lambda-declarator{opt} compound-statement
lambda-introducer:
[ lambda-capture{opt} ]
lambda-declarator:
( parameter-declaration-clause ) decl-specifier-seq{opt}
noexcept-specifier{opt} attribute-specifier-seq{opt} trailing-return-type{opt} requires-clause{opt}
In the decl-specifier-seq of the lambda-declarator, each decl-specifier shall be one of
mutable
,constexpr
, orconsteval
.
C++20 [expr.prim.lambda.capture]
lambda-capture:
capture-default
capture-list
capture-default , capture-list
capture-default:
&
=
capture-list:
capture
capture-list , capture
capture:
simple-capture
init-capture
simple-capture:
identifier ...{opt}
& identifier ...{opt}
this
* this
init-capture:
...{opt} identifier initializer
& ...{opt} identifier initializer
If a lambda-capture includes a capture-default that is
&
, no identifier in a simple-capture of that lambda-capture shall be preceded by&
. If a lambda-capture includes a capture-default that is=
, each simple-capture of that lambda-capture shall be of the form "&
identifier ...{opt}", "this
", or "* this
". [Note: The form[&,this]
is redundant but accepted for compatibility with ISO C++ 2014. -- end note]
- cpprefjp - C++20 ジェネリックラムダのテンプレート構文
- cpprefjp - C++20 ラムダ式の初期化キャプチャでのパック展開を許可
- cpprefjp - C++20 ラムダ式のキャプチャとして
[=, this]
を許可する - cpprefjp - C++20
[=]
によるthis
の暗黙のキャプチャを非推奨化 - cpprefjp - C++20 構造化束縛した変数の参照キャプチャを許可
- cpprefjp - C++20 状態を持たないラムダ式を、デフォルト構築可能、代入可能とする
- cpprefjp - C++20 評価されない文脈でのラムダ式
- ラムダキャプチャ中での前置ellipsisと後置ellipsis
- ラムダ式のcapture-defaultとthisポインタ
C++23
lambda-expression:
lambda-introducer attribute-specifier-seq{opt} lambda-declarator compound-statement
lambda-introducer < template-parameter-list > requires-clause{opt} attribute-specifier-seq{opt}
lambda-declarator compound-statement
lambda-introducer:
[ lambda-capture{opt} ]
lambda-declarator:
lambda-specifier-seq noexcept-specifier{opt} attribute-specifier-seq{opt} trailing-return-type{opt}
noexcept-specifier attribute-specifier-seq{opt} trailing-return-type{opt}
trailing-return-type{opt}
( parameter-declaration-clause ) lambda-specifier-seq{opt} noexcept-specifier{opt} attribute-specifier-seq{opt}
trailing-return-type{opt} requires-clause{opt}
lambda-specifier:
consteval
constexpr
mutable
static
lambda-specifier-seq:
lambda-specifier
lambda-specifier lambda-specifier-seq
A lambda-specifier-seq shall contain at most one of each lambda-specifier and shall not contain both
constexpr
andconsteval
. If the lambda-declarator contains an explicit object parameter ([dcl.fct]), then no lambda-specifier in the lambda-specifier-seq shall bemutable
orstatic
. The lambda-specifier-seq shall not contain bothmutable
andstatic
. If the lambda-specifier-seq containsstatic
, there shall be no lambda-capture.
- P1102R2 Down with ()! [Approved]
-
P0847R7 Deducing this [Approved]
- explicit object parameter;
[] (this auto&& self) {}
- 自己再帰するラムダ式 @ C++23
- explicit object parameter;
- P2036R3 Change scope of lambda trailing-return-type [Approved(DR)]
- P2173R1 Attributes on Lambda-Expressions [Approved]
-
P1169R4 static operator() [Approved]
- N4918 Editors' Report
[] () static {}
C++2c(C++26)
WIP Proposals (2024-07-23)