Perhaps you expect some kind of magic that makes character traits work. In this case, be disappointed - there is no magic. Type types are manually defined for each type. For example, consider iterator_traits
, which provides typedefs (e.g. value_type
) for iterators.
Using them, you can write
iterator_traits<vector<int>::iterator>::value_type x; iterator_traits<int*>::value_type y; // `x` and `y` have type int.
But to make this work, there is actually an explicit definition somewhere in the <iterator>
header that reads something like this:
template <typename T> struct iterator_traits<T*> { typedef T value_type;
This is a partial specialization of the iterator_traits
type for T*
type types, that is, pointers of some general type.
In the same vein, iterator_traits
specialized for other iterators, for example. typename vector<T>::iterator
.
Konrad Rudolph Oct. 20 '10 at 18:18 2010-10-20 18:18
source share