Is it possible to “store” a template parameter pack without expanding it?

后端 未结 4 1507
醉话见心
醉话见心 2020-11-27 11:01

I was experimenting with C++0x variadic templates when I stumbled upon this issue:

template < typename ...Args >
struct identities
{
    typedef Args t         


        
4条回答
  •  野性不改
    2020-11-27 11:34

    I think the reason it's not allowed is that it would be messy, and you can work around it. You need to use dependency inversion and make the struct storing the parameter pack into a factory template able to apply that parameter pack to another template.

    Something along the lines of:

    template < typename ...Args >
    struct identities
    {
        template < template class T >
        struct apply
        {
            typedef T type;
        };
    };
    
    template < template class> class T >
    struct convert_in_tuple
    {
        typedef typename T::type type;
    };
    
    typedef convert_in_tuple< identities< int, float >::apply >::type int_float_tuple;
    

提交回复
热议问题