Expanding a container to a parameter pack

Let's say I have a variational function that I cannot change like this:

void Func(int count, ...)
{ /*etc.*/ }

      

And I'm writing a variational pattern to wrap this function and make it safer:

template<typename... T>
void ToString(T... args)
{
    std::vector<CString> vstrArgs = { args... };
    Func(sizeof...(args), args...);
}

      

So my template is checking that each argument can be converted to CString. I want to do more than that, however I want to convert each argument to a CString and then pass those CStrings to Func () instead of just passing the original arguments.

What's the fastest and / or easiest way to do this? Thank.

+3


source to share


1 answer


template<typename... T>
void ToString(T... args)
{
    Func(sizeof...(args), ConvertToCString(args)...);
}

      

Where ConvertToCString

is a function that converts any item to CString. If the constructor is sufficient, it CString(args)...

will work. static_cast<CString>(args)...

will also work.



You can look at "Package Extension" from the parameter packages .

+4


source







All Articles