다음을 통해 공유


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 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.

Requirements

Header: <vector>

Namespace: std

See Also

Reference

<vector>

Thread Safety in the C++ Standard Library

Standard Template Library