C++ index of type during variadic template expansion

后端 未结 4 800
别那么骄傲
别那么骄傲 2020-12-08 21:43

I have a simple yet daunting problem I can\'t solve by myself. I have something like

template
T* create(SomeCastableType* args,         


        
4条回答
  •  萌比男神i
    2020-12-08 22:47

    You need a helper:

    #include 
    
    template 
    struct helper
    {
        static T * go(S * args)
        {
            return helper::value,
                          Tuple, I..., sizeof...(I)>::go(args);
        }
    };
    
    template 
    struct helper, I...>
    {
        static T * go(S * args)
        {
            return new T(static_cast(args[I])...);
        }
    };
    
    template 
    T * create(S * args)
    {
        return helper>::go(args);
    }
    

    Edit: Tested, seems to work.

提交回复
热议问题