You already have basically the best solution: to make a proxy class which is assignable from a bool but internally only assigns 1 bit, and is implicitly convertible to a bool
. BoolArray
would return this proxy class from operator[]
.
In fact, this is what vector<bool>
does with vector<bool>::reference
. As commenters have said, std::vector
is specialized for bool
to do exactly what you are writing. So unless this is just for learning, what you're writing is useless/redundant.