Based on C++ Primer 4th edition (i.e. pp 105),
bitset<32> bitvec;
bitvec[0].flip(); // reverses the first bit.
My question is why the second line works? Based on
http://www.cplusplus.com/reference/stl/bitset/operator[]/
bool operator[] ( size_t pos ) const;
reference operator[] ( size_t pos );
How can bitset::flit can be used on bool or reference?
Thank you
“reference” returned by operator[] is not a C++ reference, it is a special proxy class that has flip() method.
Pseudo code:
See source code of your STL implementation for details.