Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/vector bool"

From cppreference.com
< cpp‎ | container
m (Shorten template names. Use {{lc}} where appropriate.)
m (Update links.)
Line 19: Line 19:
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc hitem | Member type | Definition}}
 
{{dsc hitem | Member type | Definition}}
{{dsc inc | cpp/container/dcl list value_type | vector_bool}}
+
{{dsc inc | cpp/container/dsc value_type | vector_bool}}
{{dsc inc | cpp/container/dcl list allocator_type | vector_bool}}
+
{{dsc inc | cpp/container/dsc allocator_type | vector_bool}}
{{dsc inc | cpp/container/dcl list size_type | vector_bool}}
+
{{dsc inc | cpp/container/dsc size_type | vector_bool}}
{{dsc inc | cpp/container/dcl list difference_type | vector_bool}}
+
{{dsc inc | cpp/container/dsc difference_type | vector_bool}}
 
{{dsc class | cpp/container/vector_bool/reference | proxy class representing a reference to a single bool}}
 
{{dsc class | cpp/container/vector_bool/reference | proxy class representing a reference to a single bool}}
{{dsc inc | cpp/container/dcl list const_reference | vector_bool}}
+
{{dsc inc | cpp/container/dsc const_reference | vector_bool}}
{{dsc inc | cpp/container/dcl list pointer | vector_bool}}
+
{{dsc inc | cpp/container/dsc pointer | vector_bool}}
{{dsc inc | cpp/container/dcl list const_pointer | vector_bool}}
+
{{dsc inc | cpp/container/dsc const_pointer | vector_bool}}
{{dsc inc | cpp/container/dcl list iterator | vector_bool}}
+
{{dsc inc | cpp/container/dsc iterator | vector_bool}}
{{dsc inc | cpp/container/dcl list const_iterator | vector_bool}}
+
{{dsc inc | cpp/container/dsc const_iterator | vector_bool}}
{{dsc inc | cpp/container/dcl list reverse_iterator | vector_bool}}
+
{{dsc inc | cpp/container/dsc reverse_iterator | vector_bool}}
{{dsc inc | cpp/container/dcl list const_reverse_iterator | vector_bool}}
+
{{dsc inc | cpp/container/dsc const_reverse_iterator | vector_bool}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Member functions===
 
===Member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/container/dcl list constructor | vector}}
+
{{dsc inc | cpp/container/dsc constructor | vector}}
{{dsc inc | cpp/container/dcl list destructor | vector}}
+
{{dsc inc | cpp/container/dsc destructor | vector}}
{{dsc inc | cpp/container/dcl list operator{{=}} | vector}}
+
{{dsc inc | cpp/container/dsc operator{{=}} | vector}}
{{dsc inc | cpp/container/dcl list assign | vector}}
+
{{dsc inc | cpp/container/dsc assign | vector}}
{{dsc inc | cpp/container/dcl list get_allocator | vector}}
+
{{dsc inc | cpp/container/dsc get_allocator | vector}}
  
 
{{dsc h2 | Element access}}
 
{{dsc h2 | Element access}}
{{dsc inc | cpp/container/dcl list at | vector}}
+
{{dsc inc | cpp/container/dsc at | vector}}
{{dsc inc | cpp/container/dcl list operator_at | vector}}
+
{{dsc inc | cpp/container/dsc operator_at | vector}}
{{dsc inc | cpp/container/dcl list front | vector}}
+
{{dsc inc | cpp/container/dsc front | vector}}
{{dsc inc | cpp/container/dcl list back | vector}}
+
{{dsc inc | cpp/container/dsc back | vector}}
  
 
{{dsc h2 | Iterators}}
 
{{dsc h2 | Iterators}}
{{dsc inc | cpp/container/dcl list begin | vector}}
+
{{dsc inc | cpp/container/dsc begin | vector}}
{{dsc inc | cpp/container/dcl list end | vector}}
+
{{dsc inc | cpp/container/dsc end | vector}}
{{dsc inc | cpp/container/dcl list rbegin | vector}}
+
{{dsc inc | cpp/container/dsc rbegin | vector}}
{{dsc inc | cpp/container/dcl list rend | vector}}
+
{{dsc inc | cpp/container/dsc rend | vector}}
  
 
{{dsc h2 | Capacity}}
 
{{dsc h2 | Capacity}}
{{dsc inc | cpp/container/dcl list empty | vector}}
+
{{dsc inc | cpp/container/dsc empty | vector}}
{{dsc inc | cpp/container/dcl list size | vector}}
+
{{dsc inc | cpp/container/dsc size | vector}}
{{dsc inc | cpp/container/dcl list max_size | vector}}
+
{{dsc inc | cpp/container/dsc max_size | vector}}
{{dsc inc | cpp/container/dcl list reserve | vector}}
+
{{dsc inc | cpp/container/dsc reserve | vector}}
{{dsc inc | cpp/container/dcl list capacity | vector}}
+
{{dsc inc | cpp/container/dsc capacity | vector}}
  
 
{{dsc h2 | Modifiers}}
 
{{dsc h2 | Modifiers}}
{{dsc inc | cpp/container/dcl list clear | vector}}
+
{{dsc inc | cpp/container/dsc clear | vector}}
{{dsc inc | cpp/container/dcl list insert | vector}}
+
{{dsc inc | cpp/container/dsc insert | vector}}
{{dsc inc | cpp/container/dcl list erase | vector}}
+
{{dsc inc | cpp/container/dsc erase | vector}}
{{dsc inc | cpp/container/dcl list push_back | vector}}
+
{{dsc inc | cpp/container/dsc push_back | vector}}
{{dsc inc | cpp/container/dcl list pop_back | vector}}
+
{{dsc inc | cpp/container/dsc pop_back | vector}}
{{dsc inc | cpp/container/dcl list resize | vector}}
+
{{dsc inc | cpp/container/dsc resize | vector}}
{{dsc inc | cpp/container/dcl list swap | vector}}
+
{{dsc inc | cpp/container/dsc swap | vector}}
  
 
{{dsc h2 | {{tt|vector<bool>}} specific modifiers}}
 
{{dsc h2 | {{tt|vector<bool>}} specific modifiers}}
{{dsc inc | cpp/container/vector_bool/dcl list flip}}
+
{{dsc inc | cpp/container/vector_bool/dsc flip}}
{{dsc inc | cpp/container/vector_bool/dcl list swap}}
+
{{dsc inc | cpp/container/vector_bool/dsc swap}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Non-member functions===
 
===Non-member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/container/dcl list operator_cmp | vector}}
+
{{dsc inc | cpp/container/dsc operator_cmp | vector}}
{{dsc inc | cpp/container/dcl list swap2 | vector}}
+
{{dsc inc | cpp/container/dsc swap2 | vector}}
 
{{dsc end}}
 
{{dsc end}}
  
 
===Helper classes===
 
===Helper classes===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc inc | cpp/container/vector_bool/dcl list hash}}
+
{{dsc inc | cpp/container/vector_bool/dsc hash}}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 21:51, 31 May 2013

 
 
 
 
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

Member types

Member type Definition
value_type bool[edit]
allocator_type Allocator[edit]
size_type implementation-defined[edit]
difference_type implementation-defined[edit]
proxy class representing a reference to a single bool
(class)
const_reference bool[edit]
pointer implementation-defined[edit]
const_pointer implementation-defined[edit]
iterator

implementation-defined

(until C++20)

implementation-defined ConstexprIterator

(since C++20)
[edit]
const_iterator

implementation-defined

(until C++20)

implementation-defined ConstexprIterator

(since C++20)
[edit]
reverse_iterator std::reverse_iterator<iterator>[edit]
const_reverse_iterator std::reverse_iterator<const_iterator>[edit]

Member functions

constructs the vector
(public member function of std::vector<T,Allocator>) [edit]
destructs the vector
(public member function of std::vector<T,Allocator>) [edit]
assigns values to the container
(public member function of std::vector<T,Allocator>) [edit]
assigns values to the container
(public member function of std::vector<T,Allocator>) [edit]
returns the associated allocator
(public member function of std::vector<T,Allocator>) [edit]
Element access
access specified element with bounds checking
(public member function of std::vector<T,Allocator>) [edit]
access specified element
(public member function of std::vector<T,Allocator>) [edit]
access the first element
(public member function of std::vector<T,Allocator>) [edit]
access the last element
(public member function of std::vector<T,Allocator>) [edit]
Iterators
returns an iterator to the beginning
(public member function of std::vector<T,Allocator>) [edit]
(C++11)
returns an iterator to the end
(public member function of std::vector<T,Allocator>) [edit]
returns a reverse iterator to the beginning
(public member function of std::vector<T,Allocator>) [edit]
(C++11)
returns a reverse iterator to the end
(public member function of std::vector<T,Allocator>) [edit]
Capacity
checks whether the container is empty
(public member function of std::vector<T,Allocator>) [edit]
returns the number of elements
(public member function of std::vector<T,Allocator>) [edit]
returns the maximum possible number of elements
(public member function of std::vector<T,Allocator>) [edit]
reserves storage
(public member function of std::vector<T,Allocator>) [edit]
returns the number of elements that can be held in currently allocated storage
(public member function of std::vector<T,Allocator>) [edit]
Modifiers
clears the contents
(public member function of std::vector<T,Allocator>) [edit]
inserts elements
(public member function of std::vector<T,Allocator>) [edit]
erases elements
(public member function of std::vector<T,Allocator>) [edit]
adds an element to the end
(public member function of std::vector<T,Allocator>) [edit]
removes the last element
(public member function of std::vector<T,Allocator>) [edit]
changes the number of elements stored
(public member function of std::vector<T,Allocator>) [edit]
swaps the contents
(public member function of std::vector<T,Allocator>) [edit]
vector<bool> specific modifiers
flips all the bits
(public member function) [edit]
[static]
swaps two std::vector<bool>::references
(public static member function) [edit]

Non-member functions

(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(removed in C++20)(C++20)
lexicographically compares the values of two vectors
(function template) [edit]
specializes the std::swap algorithm
(function template) [edit]

Helper classes

hash support for std::vector<bool>
(class template specialization) [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>.

Since its representation may by optimized, std::vector<bool> does not necessarily meet all Template:concept or Template:concept requirements. For example, because std::vector<bool>::iterator is implementation-defined, it may not satisfy the Template:concept requirement. Use of algorithms such as std::search that require Template:concepts may result in either compile-time or run-time errors.