Cpp.TemplateFunction Class
Namespace: Cpp
Superclasses: AstNodeProperties
Represents the template_function nodes in the syntax tree of your code
Since R2026a
Description
The PQL class TemplateFunction represents the node template_function in the syntax tree of your code.
// example demonstrating template function nodes
template<typename T>
void foo(T t) {}
template<class U, int N>
U bar(U (&arr)[N]) { return arr[0]; }
int main() {
foo<int>(42);
int a[3] = {1,2,3};
bar<int,3>(a);
return 0;
}The code shows template function definitions foo and
bar. The class Cpp.TemplateFunction macthes with the
call to these template functions..
Predicates
| Type | Raisable | Printable |
|---|---|---|
TemplateFunction
| 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 TemplateFunction &tf)
| Matches a template_function node and returns it as tf; use this to directly select template function definitions. | This PQL defect checks for defect find_template_funcs =
when
Cpp.TemplateFunction.is(&tf)
and tf.nodeText(&txt)
raise "Found template function: \"{txt}\""
on tfIn this C++ code, the defect finds calls to function templates
template <typename T>
void foo(T t) {}
int main()
{
foo<int>(1); //matches
return 0;
} |
cast(Cpp.Node.Node node, required TemplateFunction &cast)
| Checks whether an arbitrary Cpp.Node.Node is a template_function; if so, returns it as cast for further inspection. | This PQL defect checks for nodes that can be interpreted as
defect cast_node_to_template =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.TemplateFunction.cast(node, &tf)
and tf.nodeText(&txt)
raise "Casted node to template_function: \"{txt}\""
on tfIn this C++ code, the defect finds the
template<class U, int N>
U bar(U (&arr)[N]) { return arr[0]; }
int main(){ int a[1]={0}; bar<int,1>(a); return 0; } |
isa(Cpp.Node.Node node)
| Returns true when the given node is a template_function; useful in conditional checks or negations. | This PQL defect checks whether a node is a
defect check_isa =
when
Cpp.Node.is(&node, &,&,&)
and Cpp.TemplateFunction.isa(node)
raise "Node is a template_function"
on nodeIn this C++ code, the defect identifies the syntax
node that matches with
template <typename T>
void foo(T t) {}
int main()
{
foo<int>(1); //matches
return 0;
} |
arguments(TemplateFunction self, Cpp.Node.Node &child)
| Selects the argument list from a
template_function. | This PQL defect checks for template parameter declarations inside
defect list_template_arguments =
when
Cpp.TemplateFunction.is(&tf)
and tf.arguments(&arg)
and arg.nodeText(&txt)
raise "Template parameter: \"{txt}\""
on argIn this C++ code, the defect finds the argument list
of thecall to the template function
template<class U, int N>
U bar(U (&arr)[N]) { return arr[0]; }
int main(){ int a[2]={0,1}; bar<int,2>(a); return 0; } |
name(TemplateFunction self, Cpp.Node.Node &child)
| Matches the name of the template function. | This PQL defect checks for the function name node inside a
defect find_template_names =
when
Cpp.TemplateFunction.is(&tf)
and tf.name(&nm)
and nm.nodeText(&txt)
raise "Template function name: \"{txt}\""
on nmIn this C++ code, the defect finds the name
template <typename T>
void foo(T t) {}
int main()
{
foo<int>(3); //matches
return 0;
} |
getEnclosingTemplateFunction(Cpp.Node.Node child, required TemplateFunction &parent)
| Finds the nearest parent template_function that contains the
specified child node and returns it as
parent. | This PQL defect checks for the defect enclosing_template_of_child =
when
Cpp.Node.is(&child, &,&,&)
and Cpp.TemplateFunction.getEnclosingTemplateFunction(child, &parent)
and parent.nodeText(&txt)
raise "Enclosing template function: \"{txt}\""
on parentIn this C++ code, the defect locates that the
template function
template <typename T>
void foo(T t) { (void)t; }
int main()
{
foo<int>(0); //matches
return 0;
} |
isEnclosedInTemplateFunction(Cpp.Node.Node child)
| Matches any ancestral template_function node in the syntax
tree of a child node | This PQL defect checks for a defect all_enclosing_templates =
when
Cpp.Node.is(&n, &,&,&)
and Cpp.TemplateFunction.isEnclosedInTemplateFunction(n)
and n.nodeText(&txt)
raise "Enclosed in template functions: \"{txt}\""
on nIn this C++ code, the defect locates that the template
function
template <typename T>
void foo(T t) { (void)t; }
int main()
{
foo<int>(0); //matches
return 0;
} |
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)