Partager via


vector<bool> Class

The vector<bool> class is a partial specialization of vector for elements of type bool. It has an allocator for the underlying type that's used by the specialization, which provides space optimization by storing one bool value per bit.

template<class Allocator = allocator<bool>> class vector< bool, Allocator >

Remarks

This class template specialization behaves like vector, except for the differences explained in this article.

Operations that deal with the bool type correspond to values in the container storage. allocator_traits::construct is not used to construct these values.

Typedefs

const_pointer

A typedef to a const_iterator that can serve as a constant pointer to a Boolean element of the vector<bool>.

const_reference

A typedef for bool. After initialization, it does not observe updates to the original value.

pointer

A typedef to an iterator that can serve as a pointer to a Boolean element of the vector<bool>.

Member Functions

flip

Reverses all bits in the vector<bool>.

swap

Exchanges the elements of two vector<bool>s.

operator[]

Returns a simulated reference to the vector<bool> element at a specified position.

at

Functions the same as the unspecialized vector::at function, except that it uses the proxy class vector<bool>::reference. Also see operator[].

front

Functions the same as the unspecialized vector::front function, except that it uses the proxy class vector<bool>::reference. Also see operator[].

back

Functions the same as the unspecialized vector::back function, except that it uses the proxy class vector<bool>::reference. Also see operator[].

Proxy Class

vector<bool> reference Class

A class that acts as a proxy to simulate bool& behavior, and whose objects can provide references to elements (single bits) within a vector<bool> object.

Requirements

Header: <vector>

Namespace: std

See Also

Reference

Thread Safety in the C++ Standard Library

Standard Template Library