I have the following code:
template >
class Carray {
// ...
typedef T* pointer;
ty
You shouldn't need a specialization at all here: iterator_traits
is already specialized for pointer types and if you do end up with an iterator that is a class type, you can just define those required typedef
s in the iterator class.
The problem is that in order to match the primary specialization, the compiler needs to take the arguments with which the template is used, plug them into the specialization, and see whether they match.
Consider what would happen 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 is the compiler supposed to know what T
to plug into S
or whether some S<T>::type
is really meant instead of just int
?
The problem is that the nested typedef (::type
) depends on the template parameter (T
). When this is the case in a function argument list or in a partial specialization, the type T
cannot be deduced (it is a "non-deduced context").