我想要一个Base
带有 2 个模板参数的模板类。特别地,第二个参数是一个模板参数。Derived
源自Base
与 CRTP。现在我想生成like的基类Derived
,Base<Derived,Derived::second_tmpl>
但是生成的基类与真实的基类不一样Derived
。如何传输模板?
#include <type_traits>
template<typename T, template<typename>class U>
struct Base
{
using type = Base<T,U>;
using devired_type = T;
template<typename V>
using second_tmpl = U<V>;
using second_type = second_tmpl<type>;
};
template<typename T>
struct Template
{
using type = Template<T>;
};
struct Derived
:public Base<Derived,Template>
{
};
//true
static_assert(
std::is_same<
Derived::second_type,
Template<Base<Derived,Template>>>::value,
"false");
//false
static_assert(
std::is_base_of<
Base<Derived,Derived::second_tmpl>,
Derived
>::value,
"false");
template<typename T>
using Template2 = Template<T>;
//false
static_assert(
std::is_same<
Base<Derived,Template>,
Base<Derived,Template2>
>::value,
"false");
使用与原始模板相同的模板,而不是原始模板。判断是错误的;