Specialization
vector<bool>
stores values in bits, not in
bool
variables. Since there are no pointers and references to bits in C++, elements of
vector<bool>
are not addressable. Also
vector<bool>::iterator
is not a random access iterator, unlike
vector<string>::iterator
or
vector<char>::iterator
. This causes the following code to fail:
template <typename T> void func(vector<T> & vec)
{
T & ref=vec.front(); //works with all types besides bool
}
Therefore, the best is to use
vector<char>.
Login in to like
Login in to comment