How can I get the innermost template parameter type?

后端 未结 2 674
猫巷女王i
猫巷女王i 2020-12-21 01:26

Q

In a dummy example of a class

typedef myStruct>> mv;

int is the innermost

2条回答
  •  太阳男子
    2020-12-21 01:58

    Try the following. It also returns a tuple if the template has more than one element:

    #include 
    #include 
    
    template
    struct innermost_impl
    {
        using type = T;
    };
    
    template class E, typename T>
    struct innermost_impl>
    {
        using type = typename innermost_impl::type;
    };
    
    template class E, typename... Ts>
    struct innermost_impl>
    {
        using type = std::tuple::type...>;
    };
    
    template
    using innermost = typename innermost_impl::type;
    
    template
    struct X;
    
    static_assert(std::is_same>>>, int>::value, "");
    
    int main()
    {
    }
    

提交回复
热议问题