std::vector<bool> (3) - Linux Manuals

std::vector<bool>: std::vector<bool>

NAME

std::vector<bool> - std::vector<bool>

Synopsis


Defined in header <vector>
template<class Allocator>
class vector<bool, Allocator>;


std::vector<bool> is a possibly 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 sizeof(bool) bytes.
std::vector<bool> behaves similarly to std::vector, but in order to be space efficient, it:


* Does not necessarily store its elements as a contiguous array (so &v[0] + n != &v[n])
* Exposes class std::vector<bool>::reference as a method of accessing individual bits. In particular, objects of this class are returned by operator[] by value.
* Does not use std::allocator_traits::construct to construct bit values.
* Does not guarantee that different elements in the same container can be modified concurrently by different threads.

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
reference (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>

Member functions


              constructs the vector
constructor (public member function of std::vector<T,Allocator>)
              destructs the vector
destructor (public member function of std::vector<T,Allocator>)
              assigns values to the container
operator= (public member function of std::vector<T,Allocator>)
              assigns values to the container
assign (public member function of std::vector<T,Allocator>)
              returns the associated allocator
get_allocator (public member function of std::vector<T,Allocator>)

Element access


              access specified element with bounds checking
at (public member function of std::vector<T,Allocator>)
              access specified element
operator[] (public member function of std::vector<T,Allocator>)
              access the first element
front (public member function of std::vector<T,Allocator>)
              access the last element
back (public member function of std::vector<T,Allocator>)

Iterators


begin returns an iterator to the beginning
cbegin (public member function of std::vector<T,Allocator>)


end_ returns an iterator to the end
cend (public member function of std::vector<T,Allocator>)


rbegin returns a reverse iterator to the beginning
crbegin (public member function of std::vector<T,Allocator>)


rend returns a reverse iterator to the end
crend (public member function of std::vector<T,Allocator>)

Capacity


              checks whether the container is empty
empty (public member function of std::vector<T,Allocator>)
              returns the number of elements
size (public member function of std::vector<T,Allocator>)
              returns the maximum possible number of elements
max_size (public member function of std::vector<T,Allocator>)
              reserves storage
reserve (public member function of std::vector<T,Allocator>)
              returns the number of elements that can be held in currently allocated storage
capacity (public member function of std::vector<T,Allocator>)

Modifiers


              clears the contents
clear (public member function of std::vector<T,Allocator>)
              inserts elements
insert (public member function of std::vector<T,Allocator>)


emplace constructs element in-place
              (public member function of std::vector<T,Allocator>)
(C++14)
              erases elements
erase (public member function of std::vector<T,Allocator>)
              adds an element to the end
push_back (public member function of std::vector<T,Allocator>)


emplace_back constructs elements in-place at the end
              (public member function of std::vector<T,Allocator>)
(C++14)
              removes the last element
pop_back (public member function of std::vector<T,Allocator>)
              changes the number of elements stored
resize (public member function of std::vector<T,Allocator>)
              swaps the contents
swap (public member function of std::vector<T,Allocator>)

vector<bool> specific modifiers


              flips all the bits
flip (public member function)


swap swaps two std::vector<bool>::references
              (public static member function)
[static]

Non-member functions


operator==
operator!= lexicographically compares the values in the vector
operator< (function template)
operator<=
operator>
operator>=
                       specializes the std::swap algorithm
std::swap(std::vector) (function template)

Helper classes


std::hash<std::vector<bool>> hash support for std::vector<bool>
                             (class template specialization)
(C++11)

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>.
Since its representation may by optimized, std::vector<bool> does not necessarily meet all Container or SequenceContainer requirements. For example, because std::vector<bool>::iterator is implementation-defined, it may not satisfy the LegacyForwardIterator requirement. Use of algorithms such as std::search that require LegacyForwardIterators may result in either_compile-time_or_run-time_errors.
The Boost.Container_version_of_vector does not specialize for bool.