As the subject, here is the related code (check https://godbolt.org/z/tDg9yG):
#include <vector>
int main()
{
std::vector<bool> v(10);
for (auto& e : v)
e = true;
}
The compiling error:
<source>:6:16: error: non-const lvalue reference to type 'std::_Bit_reference' cannot bind to a temporary of type 'std::_Bit_iterator::reference' (aka 'std::_Bit_reference')
for (auto& e : v)
^ ~
/opt/compiler-explorer/gcc-9.3.0/lib/gcc/x86_64-linux-gnu/9.3.0/../../../../include/c++/9.3.0/bits/stl_bvector.h:811:7: note: selected 'begin' function with iterator type 'std::vector<bool, type-parameter-0-0>::iterator' (aka 'std::_Bit_iterator')
begin() _GLIBCXX_NOEXCEPT
Here is the code which compiles: #include #include
int main()
{
std::vector<int> v(10);
for (auto& e : v)
e = 1;
std::cout << v.front() <<std::endl;
}