But my question highlights a problem with vector<bool> - it can't work in generic code that expects vector to be contiguous, addressable with T*, and have a .data() function that gives you that. Because it doesn't.
It doesn't even support &bool_vec[0] or &*begin() - because neither return actual references, but a reference proxy class. You can't take the address of an rvalue class, so it fails to compile entirely.
It's very well defended, but on the flip side it's incompatible with a lot of generic contexts because it doesn't have the same API as vector<T> generally, only a subset of it. Some of which seems to exist solely for there to be a common subset (like the nested reference type alias).
And the worst part is it explicitly has a member function on its nested "reference" type - so currently it can't be left unspecialised by an implementation.
View all comments
Show parent comment
2
u/TheThiefMaster 9d ago
But my question highlights a problem with
vector<bool>- it can't work in generic code that expects vector to be contiguous, addressable withT*, and have a.data()function that gives you that. Because it doesn't.It doesn't even support
&bool_vec[0]or&*begin()- because neither return actual references, but a reference proxy class. You can't take the address of an rvalue class, so it fails to compile entirely.It's very well defended, but on the flip side it's incompatible with a lot of generic contexts because it doesn't have the same API as
vector<T>generally, only a subset of it. Some of which seems to exist solely for there to be a common subset (like the nested reference type alias).And the worst part is it explicitly has a member function on its nested "reference" type - so currently it can't be left unspecialised by an implementation.