If I have a vector<bool> vec_bool
then I cannot modify the contents of the vector using the |=
assignment operator. That is, the lines
vec_bool[0] |= true;
vec_bool[0] |= vec_bool[1];
give compiler errors, while the lines
bool a = false;
a |= true;
a |= vec_bool[0];
vec_bool[0] = vec_bool[0] | vec_bool[1];
vec_bool[0] = vec_bool[0] || vec_bool[1];
vector<int> vec_int(3);
vec_int[0] |= vec_int[1];
do not. What is the reason for this?
The error given (by gcc) is:
test.cpp:21:17: error: no match for ‘operator|=’ (operand types are ‘std::vector::reference {aka std::_Bit_reference}’ and ‘bool’)
std::vector<bool>
is not an ordinary vector. It's not an actual vector ofbool
, but more like a vector of bits, whose implementation is not specified by the C++ specification. – VarienThis container is an aggregate type with the same semantics as a struct holding a C-style array T[N] as its only non-static data member.
[...]). However you lose the ability to resize it. For example. – Breakoutvector<bool>
. It is not a vector. It does not storebool
s" – Septuplicate