I have a templated class that has a data member of type std::vector<T>
, where T is also a parameter of my templated class.
In my template class I have quite some logic that does this:
T &value = m_vector[index];
This doesn't seem to compile when T is a boolean, because the [] operator of std::vector does not return a bool-reference, but a different type.
Some alternatives (although I don't like any of them):
- tell my users that they must not use bool as template parameter
- have a specialization of my class for bool (but this requires some code duplication)
Isn't there a way to tell std::vector not to specialize for bool?
typename std::vector<T>::reference_type
? – Downstreamstd::vector<bool>
, too? Kind of an adapter template, that is the same for everything except bool. But for all I know,std::vector<bool>
is quite an oddball anyway, and breaks a lot of stuff. – Urbanaboost::container::vector
doesn't have the bool specialization. That could be used instead of the std one. – Ambiguous