I was trying to do the following:
std::bitset<2000> a_bit_set{};
auto& a_bit = a_bit_set[5];
if (complicated_predicate(a_bit, other_params))
{
a_bit.flip();
}
but clang complains:
non-const lvalue reference to type 'std::bitset<2000>::reference' cannot bind to a temporary of type 'std::bitset<2000>::reference'
I am suspecting this is because the operator[] is returning a rvalue rather than a lvalue here. But according to cppreference, there is a special class std::bitset<>::reference that should allow me to reference a particular bit in a bitset. My question is: Can I get a lvalue reference to a particular bit in a bitset (akastd::bitset<>::reference)?