mercredi 21 janvier 2015

Tuple and variadic templates, how this works?

I have seen people write(on stack overflow itself, asking some even advanced concept) something along the lines of the following:



template<typename... args>
std::tuple<args...> parse(istream stream)
{
return std::make_tuple(args(stream)...);
}


and use it as



auto tup = parse<int, float, char>(stream);


How does the above code construct the tuple by parsing the stream? Is there any specific requirements on the way in which data be put into the stream?


I want to make something like this work for a char buffer from which I have to construct a tuple of int/char/float/etc. combination in exactly the same way. But even after reading stuff related to tuples and variadic templates online, I am not able to understand how the above code works. Please help


Aucun commentaire:

Enregistrer un commentaire