You don't need specialization here: iterator_traits
already specialized for pointer types, and if you end up with an iterator, which is a class type, you can simply define the required typedef
in the iterator class.
The problem is that to match the primary specialization, the compiler must accept the arguments that the template is used with, connect them to the specialization, and see if they match.
Consider what happens in the following simplified scenario:
template <typename T> struct S { typedef int type; }; template <typename T> struct Traits { }; template <typename T> struct Traits<typename S<T>::type> { };
How should the compiler know that T
for connecting to S
or is it really the value of S<T>::type
instead of just int
?
The problem is that the nested typedef ( ::type
) depends on the template parameter ( T
). If this takes place in the argument list of a function or in a partial specialization, the type T
cannot be inferred (this is a "non-derivable context").
source share