Cpp.RequiresClause Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the requires_clause nodes in the syntax tree of your code
Since R2026a
Description
The PQL class Cpp.RequiresClause represents the node requires_clause in the syntax tree of your code.
template<typename T>
requires std::integral<T>
void foo(T t) {}The requires std::integral<T> part of the example corresponds to the requires_clause node handled by Cpp.RequiresClause.
Predicates
| Type | Raisable | Printable |
|---|---|---|
RequiresClause
| 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 RequiresClause &rc)
| Checks whether a syntax node is a requires_clause and binds
it to rc. Use this to directly select requires
clauses. | This PQL defect checks for defect defectIs =
when
Cpp.RequiresClause.is(&rc)
and rc.nodeText(&txt)
raise "RequiresClause.is matched: \"{txt}\""
on rcIn this C++ code the defect finds the
template<typename T>
requires (sizeof(T) <= 8 && sizeof(T) >= 1)
void foo(T) {}
int main() {
foo(42); // OK - int satisfies the requirements
foo('a'); // OK - char satisfies the requirements
return 0;
}
|
cast(Cpp.Node.Node node, required RequiresClause &cast)
| Treats an arbitrary Node as a
requires_clause if its runtime kind matches and binds it to
cast. Use this when you have a generic node and need
requires_clause-specific predicates. | This PQL defect checks for defect defectCast =
when
Cpp.TemplateDeclaration.is(&td)
and td.getADescendant(&node)
and Cpp.RequiresClause.cast(node, &rc)
and rc.nodeText(&txt)
raise "RequiresClause.cast matched: \"{txt}\""
on rcIn this C++ code the defect finds a
template<typename T>
requires (sizeof(T) <= 8 && sizeof(T) >= 1)
void foo(T) {}
int main() {
foo(42); // OK - int satisfies the requirements
foo('a'); // OK - char satisfies the requirements
return 0;
}
|
isa(Cpp.Node.Node node)
| Checks whether a generic Node is a
requires_clause without binding it. Use this for boolean tests
or negations. | This PQL defect checks whether a generic defect defectIsa =
when
Cpp.TemplateDeclaration.is(&td)
and td.getADescendant(&node)
and Cpp.RequiresClause.isa(node)
raise "Node is a RequiresClause"
on tdIn this C++ code the defect verifies that a
template declaration contains a
template<typename T>
requires (sizeof(T) <= 8 && sizeof(T) >= 1)
void foo(T) {}
int main() {
foo(42); // OK - int satisfies the requirements
foo('a'); // OK - char satisfies the requirements
return 0;
}
|
constraint(RequiresClause self, Cpp.Node.Node &child)
| Selects the constraint expression node inside a
requires_clause and binds it to child. Use
this to inspect the concept or expression following
requires. | This PQL defect checks for the constraint expression inside a
defect defectConstraint =
when
Cpp.RequiresClause.is(&rc)
and rc.constraint(&constraint)
and constraint.nodeText(&txt)
raise "RequiresClause.constraint matched: \"{txt}\""
on constraintIn this C++ code the defect extracts the
#include <concepts>
template<typename T>
requires std::integral<T>
void foo(T) {}
int main() {} |
getEnclosingRequiresClause(Cpp.Node.Node child, required RequiresClause
&parent)
| Finds the nearest enclosing requires_clause that contains
child and binds it to parent. Use this to
map inner nodes back to their requires context. | This PQL defect checks for the nearest enclosing
defect defectEnclosing =
when
Cpp.TypeIdentifier.is(&id)
and id.toNode(&node)
and Cpp.RequiresClause.getEnclosingRequiresClause(node, &rc)
raise "Identifier is inside requires clause"
on idIn this C++ code the defect finds type identifiers
that appear inside a
#include <concepts>
template<typename T>
requires std::integral<T>
void foo(T) {}
int main() {} |
isEnclosedInRequiresClause(Cpp.Node.Node child)
| Checks whether child has any
requires_clause ancestor. Use this to filter nodes that appear
within requires clauses. | This PQL defect checks whether a given type identifier is anywhere inside
a
defect defectIsEnclosed =
when
Cpp.TypeIdentifier.is(&id)
and id.toNode(&node)
and Cpp.RequiresClause.isEnclosedInRequiresClause(node)
raise "Identifier enclosed in requires clause"
on idIn this C++ code the defect flags type identifiers
that belong to the
#include <concepts>
template<typename T>
requires std::integral<T>
void foo(T) {}
int main() {} |
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)