In C++ templated classes, each instantiation of the template is a completely different class - there is as much difference between vector<int *>
and vector<const int *>
as there is between vector<int *>
and vector<string>
or any other two classes for that matter.
It is possible that the committee could have added a conversion operator on vector
to vector<U>
as Earwicker suggests - and you can go ahead and provide your own implementation of such a function:
template <class A, class T>
vector<T> convert_vector(const vector<A> &other)
{
vector<T> newVector;
newVector.assign(other.begin(), other.end());
return newVector;
}
and use it like so:
vector<int*> v1;
vector<const int*> v2;
v2 = convert_vector<const int*>(v1);
Unfortunately, until C++0x comes with it's move constructors, this will be pretty bad performance-wise.