Skip to content

Commit 7c0c4fb

Browse files
committed
refactor: move has_template_parameter_named one scope up
1 parent baa2185 commit 7c0c4fb

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

source/cppfront.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,20 +1730,24 @@ class cppfront
17301730
}
17311731

17321732

1733+
auto has_template_parameter_named(declaration_node const& decl, token const& id)
1734+
-> bool
1735+
{
1736+
if (auto& params = decl.template_parameters) {
1737+
return std::any_of(params->parameters.begin(), params->parameters.end(), [&](auto& param) {
1738+
assert(param->has_name());
1739+
return *param->name() == id;
1740+
});
1741+
}
1742+
return false;
1743+
}
1744+
17331745
auto is_template_parameter(token const& lookup_id)
17341746
-> bool
17351747
{
17361748
// If any parent declaration
17371749
return std::any_of(current_declarations.begin() + 1, current_declarations.end(), [&](auto& decl) {
1738-
// has a template parameter
1739-
if (auto& params = decl->template_parameters) {
1740-
return std::any_of(params->parameters.begin(), params->parameters.end(), [&](auto& param) {
1741-
// of equal name.
1742-
assert(param->has_name());
1743-
return *param->name() == lookup_id;
1744-
});
1745-
}
1746-
return false;
1750+
return has_template_parameter_named(*decl, lookup_id);
17471751
});
17481752
}
17491753

@@ -3928,22 +3932,11 @@ class cppfront
39283932
-> bool
39293933
{
39303934
assert( current_declarations.back() );
3931-
auto has_template_parameter = [&](declaration_node const* decl, token const* id) {
3932-
// If `decl` has a template parameter
3933-
if (auto& params = decl->template_parameters) {
3934-
return std::any_of(params->parameters.begin(), params->parameters.end(), [&](auto& param) {
3935-
assert(param->has_name());
3936-
// of equal name.
3937-
return *param->name() == *id;
3938-
});
3939-
}
3940-
return false;
3941-
};
3942-
return has_template_parameter(current_declarations.back(), &lookup_id)
3935+
return has_template_parameter_named(*current_declarations.back(), lookup_id)
39433936
|| (
39443937
current_declarations.back()->parent_is_type()
39453938
&& current_declarations.back()->has_name("operator=")
3946-
&& has_template_parameter(current_declarations.back()->get_parent(), &lookup_id)
3939+
&& has_template_parameter_named(*current_declarations.back()->get_parent(), lookup_id)
39473940
);
39483941
}
39493942

0 commit comments

Comments
 (0)