Fixed t00044
This commit is contained in:
@@ -108,17 +108,59 @@ void template_parameter::is_variadic(bool is_variadic) noexcept
|
||||
|
||||
bool template_parameter::is_variadic() const noexcept { return is_variadic_; }
|
||||
|
||||
bool template_parameter::is_specialization_of(
|
||||
int template_parameter::calculate_specialization_match(
|
||||
const template_parameter &ct) const
|
||||
{
|
||||
if(is_function_template() && ct.is_function_template()) {
|
||||
bool res{true};
|
||||
|
||||
int res{0};
|
||||
|
||||
if (ct.type().has_value() && type().has_value() &&
|
||||
!ct.is_template_parameter() && !is_template_parameter() &&
|
||||
ct.type().value() != type().value())
|
||||
return 0;
|
||||
|
||||
if (ct.is_function_template() && !is_function_template())
|
||||
return 0;
|
||||
|
||||
if (template_params().size() > 0 && ct.template_params().size() > 0) {
|
||||
// More generic template params
|
||||
const auto &template_params = ct.template_params();
|
||||
const auto &specialization_params = this->template_params();
|
||||
auto template_index{0U};
|
||||
auto arg_index{0U};
|
||||
|
||||
while (arg_index < specialization_params.size() &&
|
||||
template_index < template_params.size()) {
|
||||
auto match = specialization_params.at(arg_index)
|
||||
.calculate_specialization_match(
|
||||
template_params.at(template_index));
|
||||
|
||||
if (match == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!template_params.at(template_index).is_variadic())
|
||||
template_index++;
|
||||
|
||||
res += match;
|
||||
|
||||
// Add 1 point for argument match
|
||||
if (!specialization_params.at(arg_index).is_template_parameter())
|
||||
res++;
|
||||
|
||||
arg_index++;
|
||||
}
|
||||
|
||||
if (arg_index == specialization_params.size())
|
||||
return res;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (ct.is_template_parameter() ||
|
||||
ct.is_template_template_parameter()) &&
|
||||
!is_template_parameter();
|
||||
if ((ct.is_template_parameter() || ct.is_template_template_parameter()) &&
|
||||
!is_template_parameter())
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void template_parameter::add_template_param(template_parameter &&ct)
|
||||
|
||||
@@ -52,6 +52,7 @@ public:
|
||||
p.set_kind(template_parameter_kind_t::template_type);
|
||||
p.set_name(name);
|
||||
p.is_variadic(is_variadic);
|
||||
p.is_template_parameter(true);
|
||||
if (default_value)
|
||||
p.set_default_value(default_value.value());
|
||||
return p;
|
||||
@@ -121,7 +122,7 @@ public:
|
||||
void is_variadic(bool is_variadic) noexcept;
|
||||
bool is_variadic() const noexcept;
|
||||
|
||||
bool is_specialization_of(const template_parameter &ct) const;
|
||||
int calculate_specialization_match(const template_parameter &ct) const;
|
||||
|
||||
friend bool operator==(
|
||||
const template_parameter &l, const template_parameter &r);
|
||||
|
||||
@@ -66,12 +66,7 @@ const std::vector<template_parameter> &template_trait::templates() const
|
||||
int template_trait::calculate_template_specialization_match(
|
||||
const template_trait &other, const std::string & /*full_name*/) const
|
||||
{
|
||||
int res{};
|
||||
|
||||
// TODO: handle variadic templates
|
||||
if (templates().size() != other.templates().size()) {
|
||||
return res;
|
||||
}
|
||||
int res{0};
|
||||
|
||||
// Iterate over all template arguments
|
||||
for (auto i = 0U; i < other.templates().size(); i++) {
|
||||
@@ -80,9 +75,17 @@ int template_trait::calculate_template_specialization_match(
|
||||
|
||||
if (template_arg == other_template_arg) {
|
||||
res++;
|
||||
|
||||
if (!template_arg.is_template_parameter())
|
||||
res++;
|
||||
|
||||
if (!other_template_arg.is_template_parameter())
|
||||
res++;
|
||||
}
|
||||
else if (other_template_arg.is_specialization_of(template_arg)) {
|
||||
continue;
|
||||
else if (auto match = other_template_arg.calculate_specialization_match(
|
||||
template_arg);
|
||||
match > 0) {
|
||||
res += match;
|
||||
}
|
||||
else {
|
||||
res = 0;
|
||||
|
||||
Reference in New Issue
Block a user