Yes, you have to anyway.
Let's re-iterate my last reply:
The compiler isn't able to deduce the type because
std::vector::iterator is a non-deductible context. It is what it is: A context where the compiler is unable to deduce a type from a given expression and/or statement.
iterator and
const_iterator are type-definitions within
std::vector; these are dependant names; that is, they depend on a template parameters/value. Since the type used in the type-definition of both iterator classes may not be the same underlying type as template-parameter for the
std::vector, the compiler cannot assume the two types are related. For instance:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
template <typename T>
class normal_iterator { };
template <typename T>
class normal_iterator<T const> { };
template <typename T>
class vector
{
public:
typedef normal_iterator<T> iterator;
typedef normal_iterator<T const> const_iterator;
};
|
In this example,
iterator is dependant on the template-parameter
T of
vector. The compiler could easily deduce the type. However, this is not always the case, and for the compiler to assume
iterator and
const_iterator depend on the template-parameter
T of
vector is dangerous.
Wazzak