Added test case for recursive variadic template specialization

This commit is contained in:
Bartek Kryza
2022-08-07 23:08:37 +02:00
parent 1844b992aa
commit ae7ef11e43
20 changed files with 416 additions and 130 deletions

View File

@@ -31,15 +31,37 @@ template_parameter::template_parameter(const std::string &type,
set_type(type);
}
void template_parameter::set_type(const std::string &type) { type_ = type; }
void template_parameter::set_type(const std::string &type)
{
if (util::ends_with(type, std::string{"..."})) {
type_ = type.substr(0, type.size() - 3);
is_variadic_ = true;
}
else
type_ = type;
}
std::string template_parameter::type() const { return type_; }
std::string template_parameter::type() const
{
if (is_variadic_ && !type_.empty())
return type_ + "...";
void template_parameter::set_name(const std::string &name) { name_ = name; }
return type_;
}
void template_parameter::set_name(const std::string &name)
{
if (util::ends_with(name, std::string{"..."})) {
name_ = name.substr(0, name.size() - 3);
is_variadic_ = true;
}
else
name_ = name;
}
std::string template_parameter::name() const
{
if (is_variadic_)
if (is_variadic_ && type_.empty())
return name_ + "...";
return name_;

View File

@@ -54,6 +54,9 @@ public:
void is_variadic(bool is_variadic) noexcept;
bool is_variadic() const noexcept;
void is_pack(bool is_pack) noexcept;
bool is_pack() const noexcept;
bool is_specialization_of(const template_parameter &ct) const;
friend bool operator==(
@@ -118,6 +121,9 @@ private:
/// Whether the template parameter is variadic
bool is_variadic_{false};
/// Whether the argument specializes argument pack from parent template
bool is_pack_{false};
// Nested template parameters
std::vector<template_parameter> template_params_;