Pregunta

I'm reading through Modern C++ Design and the thought occurred to me that the typelist construct may be replacable by variadic templates. Both seem to rely on recursion to process the first type in the list and the remainder of the list separately. Is there anything typelists allow you to do that a variadic template wouldn't?

¿Fue útil?

Solución

Typelists allow you a few things. For example, you cannot have a variadic argument pack as the result of a metafunction - there's just no way to express something like this:

template <typename... Args>
struct argpack_id {
    typedef Args result;
};

You can do this with typelists.

On the other hand, you should probably implement the typelist itself as

template <typename... Args>
struct TypeList {};
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top