开发者

Extract variadic template parameter pack and use it in another variadic template in a type traits meta-function?

I want to determine if any variadic class template is the base of another class. Typically I'd use std::is_base_of, but I don't think my use case fits, and I'm not sure if there's already something in std or boost to handle this. I want the variadic base class template's parameter pack to come from another variadic class template. Here's some example code that hopefully explains what I want to do:

Usage:

is_variadic_base_of<
   VarClassTemplA
   , ClassDerivedFromA
   , VarClassTemplB //Has param pack I want to use with ClassA
>::value;

Guts:

//test for variad开发者_如何转开发ic base of non-variadic
template <template<typename...> class A, typename B, typename... ArgsC>
struct is_variadic_base_of
: std::is_base_of<A<ArgsC...>, B>
{};

Is this possible?


template <template<typename...> class A, typename B, typename ArgsC>
struct is_variadic_base_of;

template <template<typename...> class A, typename B, 
          template<typename...> class C, typename ...ArgsC>
struct is_variadic_base_of<A, B, C<ArgsC...>> 
: std::is_base_of<A<ArgsC...>, B>
{};

Hope it helps!


You're nearly there, but try it with a partial specialization:

template<
    template<class...> class A, class B, class C
>
struct is_variadic_base_of;

// partial spec
template<
    template<class...> class A, class B,
    template<class...> class C, class... ArgsC
>
struct is_variadic_base_of< A,B,C<ArgsC...> >
  : std::is_base_of< A<ArgsC...>,B >
{};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜