How to transmit a template?

本秂侑毒 提交于 2019-12-06 07:54:36

These are the limitations of tempalte template arguments.

Template template arguments are second-class citizens in C++ :(

The second assert should really read

static_assert(std::is_base_of<Base<Derived, Template>, Derived>::value, "false");

which would work.

To combat the problem with the third (the fact that you "can't typedef an open template"), make it a meta-function: e.g. with TemplateGen in the below program:

Live On Coliru

#include <type_traits>

template <typename T, typename UGen>
struct Base {
    using type = Base<T, typename UGen::template type<T> >;
    using devired_type = T;

    template <typename V> using second_tmpl = typename UGen::template type<T> ;
    using second_type = second_tmpl<type>;
};

template <typename T>
struct Template {
    using type = Template<T>;
};

struct TemplateGen {
    template <typename T> using type = Template<T>;
};

struct Derived : public Base<Derived, TemplateGen> {
};

// true
static_assert(std::is_same<Derived::second_type, Template<Derived> >::value, "false");
// false
static_assert(std::is_base_of<Base<Derived, TemplateGen>, Derived>::value, "false");

using Template2 = TemplateGen;

// false
static_assert(std::is_same<Base<Derived, TemplateGen>, Base<Derived, Template2>>::value, "false");

int main(){}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!