相关疑难解决方法(0)

匹配别名模板作为模板参数

请考虑以下代码:

#include <type_traits>

template<template<class...> class T, class... U>
struct is_specialization_of : std::false_type{};

template<template<class...> class T, class... U>
struct is_specialization_of<T, T<U...>> : std::true_type{};

template<class T, class U = int>
struct test{};

// (1) ok
static_assert(is_specialization_of<test, test<int>>::value, "1");

template<class T>
using alias = test<T>;

// (2) fails
static_assert(is_specialization_of<alias, alias<int>>::value, "2");

int main()
{
}
Run Code Online (Sandbox Code Playgroud)

为什么(2),即static_assert使用别名模板,失败?

(2)中的模板参数推导过程与(1)中的模板参数推导过程有何不同?

c++ templates language-lawyer c++11

14
推荐指数
1
解决办法
573
查看次数

标签 统计

c++ ×1

c++11 ×1

language-lawyer ×1

templates ×1