Call variadic templated function with arguments from a std::vector

  c++, c++17, variadic-templates

I need to convert elements of a std::vector to types based on a template parameter and call a function with these parameters. In pseudocode:

template <typename T...>
void foo(std::vector<std::string> v) {
    if (v.size() != sizeof...(T))
        throw std::runtime_error("Bad");

    bar(convert<T0>(v[0]), convert<T1>(v[1]), ..., convert<Tn>(v[n]));
}

My problem is how to obtain the element indices from the parameter pack, I think there will be some kind of a trick using fold expressions, but I can’t figure it out.

Source: Windows Questions C++

LEAVE A COMMENT