Я пытаюсь «перегрузить» функцию шаблона в классе, в зависимости от родительского класса шаблона аргумента специализации. Однако я получаю следующую ошибку.
ошибка C2938: 'std::enable_if_t': Не удалось специализировать шаблон псевдонима
#include
#include
template
struct test_base_template;
template
using is_base_template_of = typename test_base_template::is_base;
//Derive - is a class. Let inherit from Derive, so it can cast to its protected parents
template
struct test_base_template : Derived
{
template
static constexpr std::true_type test(BaseTemplate*);
static constexpr std::false_type test(...);
using is_base = decltype(test((test_base_template*) nullptr));
};
//Derive - is not a class, so it always false
template
struct test_base_template>
{
using is_base = std::false_type;
};
template
class MyClass
{
public:
template
std::shared_ptr get()
{
return m_data.lock();
}
template
std::shared_ptr get()
{
return m_data;
}
private:
type m_data;
};
int main()
{
MyClass t;
auto a1 = t.get();
MyClass t2;
auto a2 = t2.get();
}
Прочитал эту тему std::is_base_of для классов шаблонов
Я пытаюсь «перегрузить» функцию шаблона в классе, в зависимости от родительского класса шаблона аргумента специализации. Однако я получаю следующую ошибку.
ошибка C2938: 'std::enable_if_t': Не удалось специализировать шаблон псевдонима
Что здесь не так? [code]#include #include
template struct test_base_template;
template using is_base_template_of = typename test_base_template::is_base;
//Derive - is a class. Let inherit from Derive, so it can cast to its protected parents template struct test_base_template : Derived { template static constexpr std::true_type test(BaseTemplate*); static constexpr std::false_type test(...); using is_base = decltype(test((test_base_template*) nullptr)); };
//Derive - is not a class, so it always false template struct test_base_template> { using is_base = std::false_type; };