vector<bool>::reference
Class
The vector<bool>::reference
class is a proxy class provided by the vector<bool> Class to simulate bool&
.
Remarks
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 tries to use 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
Member function | Description |
---|---|
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. |
Requirements
Header: <vector>
Namespace: std
See also
<vector>
Thread Safety in the C++ Standard Library
C++ Standard Library Reference
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for