문제

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?

도움이 되었습니까?

해결책

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 {};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top