How can I pull variadic template arguments off from the tail instead of the head?

后端 未结 4 1252
离开以前
离开以前 2021-02-04 13:10

For silly reasons I\'ll not go into here, I need the commented out line to work and the line above it it to not work:

template
         


        
4条回答
  •  没有蜡笔的小新
    2021-02-04 13:28

    I've been playing with it all night and finally got something to work (changed my casing to match the STL):

    template
    struct reverse_tuple_outer
    {
        template
        struct reverse_tuple_inner: reverse_tuple_outer<_N-1, _Head, _All...>::template reverse_tuple_inner<_Tail...> { };
    };
    
    template
    struct reverse_tuple_outer<0, _All...>
    {
        template
        struct reverse_tuple_inner {
            typedef std::tuple<_All...> type;
        };
    };
    
    template
    struct reverse_tuple
    {
        typedef typename reverse_tuple_outer::template reverse_tuple_inner<_Args...>::type type;
    };
    
    template
    struct strip_and_reverse_tuple;
    
    template
    struct strip_and_reverse_tuple>
    {
        typedef typename reverse_tuple<_Args...>::type type;
    };
    
    template
    struct partial_tuple
    {
        typedef typename strip_and_reverse_tuple::template reverse_tuple_inner<_Args...>::type>::type type;
    };
    
    int main()
    {
        //partial_tuple<1, std::string, std::string, int, int>::type A{"test", 5, 1};
        partial_tuple<1, std::string, std::string, int, int>::type B{"test", "test", 5};
    }
    

    As an added bonus, I also have reverse_tuple, should I ever need it.

提交回复
热议问题