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

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

    template
    auto apply_impl(F&& f, Tuple&& t, std::index_sequence) {
        return std::forward(f)(std::get(std::forward(t))...);
    }
    template
    auto apply(F&& f, Tuple&& t) {
        using Indices = std::make_index_sequence>::value>;
        return apply_impl(std::forward(f), std::forward(t), Indices());
    }
    

    This is adapted from the C++14 draft using index_sequence. I might propose to have apply in a future standard (TS).

提交回复
热议问题