How to convert variadic function arguments to array? I need something like this:
template <typename T>
struct Colordata
{
public:
T dataFirst;
T dataLast;
template <typename... Ta>
Colordata(Ta... args)
{
constexpr std::size_t n = sizeof...(Ta);
std::cout << n << std::endl;
dataFirst = (args..)[0];
dataLast = (args...)[n - 1];
return;
}
};
int main(int argc, char const *argv[])
{
auto a = Colordata<float>(1.0f, 2.2f, 3.3f, 4.3f, 5.5f);
return 0;
}
I tried to use variadic arguments as T args, ... and use functions from stdarg.h but then I can't get the count of arguments.
Colordata<float>you are just specifying the type of the first argument. The rest are deduced by the compiler. In this case they are allfloats though.std::initializer_list<float>, and not a variadic array... But since it's unclear what they're doing, it's hard to give good advice.