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

前端 未结 13 1257
旧时难觅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:37

    Why not just wrap your variadic arguments into a tuple class and then use compile time recursion (see link) to retrieve the index you are interested in. I find that unpacking variadic templates into a container or collection may not be type safe w.r.t. heterogeneous types

    template
    auto get_args_as_tuple(Args... args) -> std::tuple 
    {
        return std::make_tuple(args);
    }
    

提交回复
热议问题