I need to complement the values of std::vector<bool>
. So I thought of using range for loop taking elements by reference. But the compiler is giving me the below error
error: cannot bind non-const lvalue reference of type 'std::_Bit_reference&' to an rvalue of type 'std::_Bit_iterator::reference'
13 | for (auto& bit : rep)
This is my sample code
#include <iostream>
#include <vector>
int main() {
std::vector<bool> rep;
rep.push_back(true);
rep.push_back(false);
rep.push_back(true);
rep.push_back(false);
rep.push_back(true);
rep.push_back(false);
for (auto& bit : rep)
bit = !bit;
}