Cpp.StructuredBindingDeclarator Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the structured_binding_declarator nodes in the syntax tree of your code
Since R2026a
Description
The PQL class StructuredBindingDeclarator represents the node structured_binding_declarator in the syntax tree of your code.
#include <utility>
#include <tuple>
std::pair<int,int> foo() { return {1,2}; }
void bar() {
auto [x, y] = foo(); // structured_binding_declarator node covering "x, y"
}The auto [x, y] = foo(); line contains the
structured_binding_declarator node.
Predicates
| Type | Raisable | Printable |
|---|---|---|
StructuredBindingDeclarator
| 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 StructuredBindingDeclarator &sbd)
| Matches a structured_binding_declarator node and returns it as &sbd. Use this to directly select structured binding declarators. |
This PQL defect checks for any structured binding declarator node in the source. defect find_sbd =
when
Cpp.StructuredBindingDeclarator.is(&sbd)
and sbd.nodeText(&txt)
raise "Found structured binding: \"{txt}\""
on sbdIn this C++ code, the defect finds the structured binding declarator that declares
#include <utility>
std::pair<int,int> foo() { return {1,2}; }
void f() {
auto [x, y] = foo(); // matches
} |
cast(Cpp.Node.Node node, required StructuredBindingDeclarator &cast)
| Checks whether a generic Cpp.Node.Node is a structured_binding_declarator and, if so, returns it as &cast. Use when you have a node of unknown kind. |
This PQL defect checks whether a generic node is a structured binding declarator. defect cast_to_sbd =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.StructuredBindingDeclarator.cast(node, &sbd)
and sbd.nodeText(&txt)
raise "Casted to structured binding: \"{txt}\""
on sbdIn this C++ code, the defect detects the structured binding by first treating the parse node generically and then casting it.
#include <utility>
std::pair<int,int> foo() { return {1,2}; }
void g() {
auto [a, b] = foo(); // matches
} |
isa(Cpp.Node.Node node)
| Returns true if the given Cpp.Node.Node is a structured_binding_declarator; use for boolean checks or negation (not ... isa(node)). |
This PQL defect checks for nodes that are structured binding declarators using a boolean test. defect isa_check =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.StructuredBindingDeclarator.isa(node)
raise "Node is a structured binding declarator"
on nodeIn this C++ code, the defect confirms that the parsed node corresponding to the bracketed declarator is a structured binding.
#include <tuple>
std::tuple<int,int> t() { return {1,2}; }
void h() {
auto [p, q] = t(); // matches
} |
identifier(StructuredBindingDeclarator self, Cpp.Node.Node &child)
| Enumerates each identifier child inside the structured binding (e.g., x and y in auto [x, y] = ...) and returns them as &child. |
This PQL defect checks for individual identifier nodes within a structured binding declarator. defect sbd_identifier =
when
Cpp.StructuredBindingDeclarator.is(&sbd)
and sbd.identifier(&id)
and id.nodeText(&txt)
raise "Structured binding identifier: \"{txt}\""
on idIn this C++ code, the defect finds each declared name inside the structured binding (
#include <utility>
std::pair<int,int> foo() { return {1,2}; }
void k() {
auto [x, y] = foo(); // identifier predicate matches `x` then `y`
} |
getEnclosingStructuredBindingDeclarator(Cpp.Node.Node child, required StructuredBindingDeclarator &parent)
| Finds the nearest enclosing structured_binding_declarator for a given child node and returns it as &parent. | This PQL defect checks for the parent structured binding declarator that has a generic child node. defect enclosing_sbd =
when
Cpp.Node.is(&child, &,&,&)
and Cpp.StructuredBindingDeclarator.getEnclosingStructuredBindingDeclarator(child, &parent)
and parent.nodeText(&txt)
raise "Enclosing structured binding: \"{txt}\""
on parentIn this C++ code, the defect identifies the structured binding that has child nodes.
#include <utility>
std::pair<int,int> foo() { return {1,2}; }
void m() {
auto [x, y] = foo(); // matches
} |
isEnclosedInStructuredBindingDeclarator(Cpp.Node.Node
child) | Matches any ancestor structured_binding_declarator of
child. | This PQL defect checks for the ancestor structured binding declarator that has a generic descendent node. defect enclosed_in_sbd =
when
Cpp.Node.is(&child, &,&,&)
and Cpp.StructuredBindingDeclarator.isEnclosedInStructuredBindingDeclarator(n)
raise "Node is inside structured binding declarator"
on nIn this C++ code, the defect confirms that the
identifier nodes
#include <utility>
std::pair<int,int> foo() { return {1,2}; }
void m() {
auto [x, y] = foo(); // matches
} |
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)