Cpp.LambdaExpression Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the lambda_expression nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.LambdaExpression represents the node lambda_expression in the syntax tree of your code.
#include <functional>
int main() {
auto l1 = []() { return 42; };
auto l2 = [x, &y]() { return x + y; };
auto l3 = []<typename T>(T x) { return x; };
auto l4 = []() requires true { return 0; };
auto l5 = [](int x) mutable -> int { return x; };
(void)l1; (void)l2; (void)l3; (void)l4; (void)l5;
}The code declares several lambda expressions; each lambda corresponds to a lambda_expression node that Cpp.LambdaExpression models.
Predicates
| Type | Raisable | Printable |
|---|---|---|
LambdaExpression
| Yes | No |
This class defines these predicates that act on the objects of this class. In addition, objects of this class can access the predicates defined by the base class AstNodeProperties. An object of this class is an object of AstNodeProperties class.
| Predicates | Description | Example |
|---|---|---|
is(required LambdaExpression &le)
| Checks whether a syntax node is a lambda_expression and
binds it to le for further queries. | This PQL defect checks for any lambda expression node. defect find_lambda =
when
Cpp.LambdaExpression.is(&le)
and le.nodeText(&txt)
raise "found lambda: \"{txt}\""
on leIn this C++ code, the defect finds any lambda expression declaration.
int main() {
auto l = [](){ return 1; };
(void)l;
} |
cast(Cpp.Node.Node node, required LambdaExpression &cast)
| If node is a lambda_expression then
convert it to a Cpp.LambdaExpression and bind it to
cast. | This PQL defect checks whether an arbitrary node is a lambda and casts it
to
defect cast_from_node =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.LambdaExpression.cast(node, &le)
and le.nodeText(&txt)
raise "casted node to lambda: \"{txt}\""
on leIn this C++ code, the defect tests a generic node and reports when that node is a lambda expression.
int main() {
auto lambda = [](){};
(void)lambda;
} |
isa(Cpp.Node.Node node)
| True when node is a lambda_expression
node; can be used to filter or negate matches. | This PQL defect checks whether a generic node is a lambda expression
using defect check_isa =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.LambdaExpression.isa(node)
raise "node is a lambda"
on nodeIn this C++ code, the defect identifies the lambda expression node among other nodes.
int main() {
auto f = [](int){};
(void)f;
} |
body(LambdaExpression self, Cpp.Node.Node &child)
| Retrieves the lambda's function body block or expression and binds it to
child. | This PQL defect checks for the body node inside a lambda expression. defect lambda_body =
when
Cpp.LambdaExpression.is(&le)
and le.body(&body)
and body.nodeText(&txt)
raise "lambda body: \"{txt}\""
on leIn this C++ code, the defect extracts and reports the
int main() {
auto l = [](){ return 42; };
(void)l;
} |
captures(LambdaExpression self, Cpp.Node.Node &child)
| Matches the capture list of the lambda and binds that capture node to
child. | This PQL defect checks for the capture clause of a lambda. defect lambda_captures =
when
Cpp.LambdaExpression.is(&le)
and le.captures(&cap)
and cap.nodeText(&txt)
raise "lambda captures: \"{txt}\""
on leIn this C++ code, the defect finds and reports the
capture list like
int main() {
int x = 1, y = 2;
auto l = [x, &y]() { return x + y; };
(void)l;
} |
constraint(LambdaExpression self, Cpp.Node.Node &child)
| Matches the requires-clause or constraint on a templated or constrained lambda
and binds it to child. | This PQL defect checks for a defect lambda_constraint =
when
Cpp.LambdaExpression.is(&le)
and le.constraint(&c)
and c.nodeText(&txt)
raise "lambda constraint: \"{txt}\""
on leIn this C++ code, the defect finds the
int main() {
auto l = []() requires true { return 0; };
(void)l;
} |
declarator(LambdaExpression self, Cpp.Node.Node &child)
| Matches the lambda's parameter list, mutable specifier and trailing return type
and binds that part to child. | This PQL defect checks for the declarator portion of a lambda such as
parameters, defect lambda_declarator =
when
Cpp.LambdaExpression.is(&le)
and le.declarator(&d)
and d.nodeText(&txt)
raise "lambda declarator: \"{txt}\""
on leIn this C++ code, the defect reports the
int main() {
auto l = [](int x) mutable -> int { return x; };
(void)l;
} |
template_parameters(LambdaExpression self, Cpp.Node.Node
&child)
| Matches the template parameter list of a templated lambda and binds it to
child. | This PQL defect checks for template parameters on a lambda such as
defect lambda_template_params =
when
Cpp.LambdaExpression.is(&le)
and le.template_parameters(&tp)
and tp.nodeText(&txt)
raise "lambda template parameters: \"{txt}\""
on leIn this C++ code, the defect finds the
int main() {
auto l = []<typename T>(T x){ return x; };
(void)l;
} |
getEnclosingLambdaExpression(Cpp.Node.Node child, required LambdaExpression
&parent)
| Finds the nearest enclosing lambda_expression ancestor of
child and binds it to parent. | This PQL defect checks for the closest lambda that encloses a given inner node. defect enclosing_lambda =
when
Cpp.ReturnStatement.is(&ret)
and ret.toNode(&node)
and Cpp.LambdaExpression.getEnclosingLambdaExpression(node, &le)
and le.nodeText(&txt)
raise "enclosing lambda: \"{txt}\""
on leIn this C++ code, the defect detects the lambda that
directly contains a
int main() {
auto l = [](){ return 5; };
(void)l;
} |
isEnclosedInLambdaExpression(Cpp.Node.Node child)
| True when child has a lambda_expression
ancestor anywhere above it in the tree. | This PQL defect checks whether a given node sits inside any lambda expression. defect inside_lambda =
when
Cpp.ReturnStatement.is(&ret)
and ret.toNode(&node)
and Cpp.LambdaExpression.isEnclosedInLambdaExpression(node)
raise "node is enclosed in a lambda"
on nodeIn this C++ code, the defect confirms that the
int main() {
auto l = [](){ return 7; };
(void)l;
} |
Version History
Introduced in R2026a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)