How do I expand a tuple into variadic template function's arguments?

前端 未结 13 1292
旧时难觅i
旧时难觅i 2020-11-22 07:49

Consider the case of a templated function with variadic template arguments:

template Tret func(const T&... t);
         


        
13条回答
  •  甜味超标
    2020-11-22 08:19

    This simple solution works for me:

    template
    void unwrap_tuple(std::tuple* tp)
    {
        std::cout << "And here I have the tuple types, all " << sizeof...(T) << " of them" << std::endl;
    }
    
    int main()
    {
        using TupleType = std::tuple;
    
        unwrap_tuple((TupleType*)nullptr); // trick compiler into using template param deduction
    }
    

提交回复
热议问题