Is there any way of detecting arbitrary template classes that mix types and non-types?

前端 未结 2 1307
眼角桃花
眼角桃花 2020-12-18 05:54

Is there any way of detecting whether a class is a normal type or is an instantiation of a template type (meta type) which may include non-type parameters?

相关标签:
2条回答
  • 2020-12-18 06:18

    I guess it is not possible.

    Anyway, you can use the other way around and let N be deduced:

    template<class, class> struct MixedFoo;
    template<class C, int N> struct MixedFoo<C, std::integral_constant<int, N>>{};
    

    Now, this returns true as expected:

     std::cout << is_template<MixedFoo>() << std::endl; // fails here
    

    Of course, you won't be able anymore to use MixedFoo as MixedFoo<int, 2>, so I'm not sure it's worth it.

    0 讨论(0)
  • 2020-12-18 06:27

    No, there is not.

    Note that template classes are not classes themselves. They are templates for classes.

    0 讨论(0)
提交回复
热议问题