std::vector<bool>
From cppreference.com
Defined in header <vector>
|
||
template<class Allocator = std::allocator<bool>>
class vector<bool, Allocator>; |
||
std::vector<bool> is a space-efficient specialization of std::vector for the type bool.
The manner in which std::vector<bool> is made space efficient (as well as whether it is optimized at all) is implementation defined. One potential optimization involves coalescing vector elements such that each element occupies a single bit instead of a byte-sized bool.
std::vector<bool> behaves similarly to std::vector, but in order to be space efficient, it:
- Does not necessarily store its data in a single contiguous chunk of memory.
- Exposes std::vector<bool>::reference as a method of accessing individual bits.
- Does not use std::allocator_traits::construct to construct bit values.
Contents |
[edit] Member types
Member type | Definition |
value_type
|
bool |
allocator_type
|
Allocator
|
size_type
|
implementation-defined |
difference_type
|
implementation-defined |
proxy class representing a reference to a single bool (class) |
|
const_reference
|
bool |
pointer
|
implementation-defined |
const_pointer
|
implementation-defined |
iterator
|
implementation-defined |
const_iterator
|
implementation-defined |
reverse_iterator
|
std::reverse_iterator<iterator> |
const_reverse_iterator
|
std::reverse_iterator<const_iterator> |
[edit] Member functions
constructs the vector (public member function of std::vector )
|
|
destructs the vector (public member function of std::vector )
|
|
assigns values to the container (public member function of std::vector )
|
|
assigns values to the container (public member function of std::vector )
|
|
returns the associated allocator (public member function of std::vector )
|
|
Element access | |
access specified element with bounds checking (public member function of std::vector )
|
|
access specified element (public member function of std::vector )
|
|
access the first element (public member function of std::vector )
|
|
access the last element (public member function of std::vector )
|
|
Iterators | |
returns an iterator to the beginning (public member function of std::vector )
|
|
returns an iterator to the end (public member function of std::vector )
|
|
returns a reverse iterator to the beginning (public member function of std::vector )
|
|
returns a reverse iterator to the end (public member function of std::vector )
|
|
Capacity | |
checks whether the container is empty (public member function of std::vector )
|
|
returns the number of elements (public member function of std::vector )
|
|
returns the maximum possible number of elements (public member function of std::vector )
|
|
reserves storage (public member function of std::vector )
|
|
returns the number of elements that can be held in currently allocated storage (public member function of std::vector )
|
|
Modifiers | |
clears the contents (public member function of std::vector )
|
|
inserts elements (public member function of std::vector )
|
|
erases elements (public member function of std::vector )
|
|
adds elements to the end (public member function of std::vector )
|
|
removes the last element (public member function of std::vector )
|
|
changes the number of elements stored (public member function of std::vector )
|
|
swaps the contents (public member function of std::vector )
|
|
| |
flips all the bits (public member function) |
|
[static]
|
swaps two std::vector<bool>::reference s (public static member function) |
[edit] Non-member functions
lexicographically compares the values in the vector (function template) |
|
specializes the std::swap algorithm (function template) |
[edit] Notes
If the size of the bitset is known at compile time, std::bitset may be used, which offers a richer set of member functions. In addition, boost::dynamic_bitset exists as an alternative to std::vector<bool>
.