On Thu, 18 Sep 2014 16:33:07 -0400, AP wrote:
> What is wrong with it ? I'm trying to digest Exceptional C++ on the
> subject and can't get it ...
std::vector<bool> has a relaxed specification relative to a vector of any
other type, so that the implementation can store each element as a single
bit.
Consequently, code which is valid for a vector of any other type (or even
for other containers) isn't necessarily valid for std::vector<bool>.
The main problem is that std::vector<bool>::reference won't be just
"bool&", because you can't have a reference to a bit. Instead, it will be
a proxy which emulates a reference by providing "operator bool" and
"operator=" methods.
Similarly, you can't obtain a pointer to a bit; "&v[i]" will return a
pointer to the reference proxy. In turn, there's no guarantee that
"i == j" implies "&v[i] == &v[j]" (v[i] and v[j] will probably be
different objects which reference the same bit).