vector<bool>::reference Class
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at vector<bool>::reference Class.
The vector<bool>::reference class is a proxy class provided by the vector<bool> Class to simulate bool&.
A simulated reference is required because C++ does not natively allow direct references to bits. vector<bool> uses only one bit per element, which can be referenced by using this proxy class. However, the reference simulation is not complete because certain assignments are not valid. For example, because the address of the vector<bool>::reference object cannot be taken, the following code that uses vector<bool>::operator[] is not correct:
vector<bool> vb;
...
bool* pb = &vb[1]; // conversion error - do not use
bool& refb = vb[1]; // conversion error - do not use
Member Functions
| flip | Inverts the Boolean value of a vector element. |
| operator bool | Provides an implicit conversion from vector<bool>::reference to bool. |
| operator= | Assigns a Boolean value to a bit, or the value held by a referenced element to a bit. |
Header: <vector>
Namespace: std
<vector>
Thread Safety in the C++ Standard Library
Standard Template Library