Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | container
(Undo revision 48201 by Cubbi (talk) nevermind, confusing changes in the std)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 6: Line 6:
 
}}  
 
}}  
  
{{c|std::vector<bool>}} is a space-efficient specialization of {{c|std::vector}} for the type {{c|bool}}.  
+
{{c|std::vector<bool>}} is a space-efficient specialization of {{lc|std::vector}} for the type {{c|bool}}.  
  
 
The manner in which {{c|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 {{c|bool}}.
 
The manner in which {{c|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 {{c|bool}}.
  
{{c|std::vector<bool>}} behaves similarly to {{c|std::vector}}, but in order to be space efficient, it:
+
{{c|std::vector<bool>}} behaves similarly to {{lc|std::vector}}, but in order to be space efficient, it:
  
 
* Does not necessarily store its data in a single contiguous chunk of memory.
 
* Does not necessarily store its data in a single contiguous chunk of memory.
Line 17: Line 17:
  
 
===Member types===
 
===Member types===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list hitem | Member type | Definition}}
+
{{dsc hitem | Member type | Definition}}
{{dcl list template | cpp/container/dcl list value_type | vector_bool}}
+
{{dsc inc | cpp/container/dcl list value_type | vector_bool}}
{{dcl list template | cpp/container/dcl list allocator_type | vector_bool}}
+
{{dsc inc | cpp/container/dcl list allocator_type | vector_bool}}
{{dcl list template | cpp/container/dcl list size_type | vector_bool}}
+
{{dsc inc | cpp/container/dcl list size_type | vector_bool}}
{{dcl list template | cpp/container/dcl list difference_type | vector_bool}}
+
{{dsc inc | cpp/container/dcl list difference_type | vector_bool}}
{{dcl list 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}}
{{dcl list template | cpp/container/dcl list const_reference | vector_bool}}
+
{{dsc inc | cpp/container/dcl list const_reference | vector_bool}}
{{dcl list template | cpp/container/dcl list pointer | vector_bool}}
+
{{dsc inc | cpp/container/dcl list pointer | vector_bool}}
{{dcl list template | cpp/container/dcl list const_pointer | vector_bool}}
+
{{dsc inc | cpp/container/dcl list const_pointer | vector_bool}}
{{dcl list template | cpp/container/dcl list iterator | vector_bool}}
+
{{dsc inc | cpp/container/dcl list iterator | vector_bool}}
{{dcl list template | cpp/container/dcl list const_iterator | vector_bool}}
+
{{dsc inc | cpp/container/dcl list const_iterator | vector_bool}}
{{dcl list template | cpp/container/dcl list reverse_iterator | vector_bool}}
+
{{dsc inc | cpp/container/dcl list reverse_iterator | vector_bool}}
{{dcl list template | cpp/container/dcl list const_reverse_iterator | vector_bool}}
+
{{dsc inc | cpp/container/dcl list const_reverse_iterator | vector_bool}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Member functions===
 
===Member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/container/dcl list constructor | vector}}
+
{{dsc inc | cpp/container/dcl list constructor | vector}}
{{dcl list template | cpp/container/dcl list destructor | vector}}
+
{{dsc inc | cpp/container/dcl list destructor | vector}}
{{dcl list template | cpp/container/dcl list operator{{=}} | vector}}
+
{{dsc inc | cpp/container/dcl list operator{{=}} | vector}}
{{dcl list template | cpp/container/dcl list assign | vector}}
+
{{dsc inc | cpp/container/dcl list assign | vector}}
{{dcl list template | cpp/container/dcl list get_allocator | vector}}
+
{{dsc inc | cpp/container/dcl list get_allocator | vector}}
  
{{dcl list h2 | Element access}}
+
{{dsc h2 | Element access}}
{{dcl list template | cpp/container/dcl list at | vector}}
+
{{dsc inc | cpp/container/dcl list at | vector}}
{{dcl list template | cpp/container/dcl list operator_at | vector}}
+
{{dsc inc | cpp/container/dcl list operator_at | vector}}
{{dcl list template | cpp/container/dcl list front | vector}}
+
{{dsc inc | cpp/container/dcl list front | vector}}
{{dcl list template | cpp/container/dcl list back | vector}}
+
{{dsc inc | cpp/container/dcl list back | vector}}
  
{{dcl list h2 | Iterators}}
+
{{dsc h2 | Iterators}}
{{dcl list template | cpp/container/dcl list begin | vector}}
+
{{dsc inc | cpp/container/dcl list begin | vector}}
{{dcl list template | cpp/container/dcl list end | vector}}
+
{{dsc inc | cpp/container/dcl list end | vector}}
{{dcl list template | cpp/container/dcl list rbegin | vector}}
+
{{dsc inc | cpp/container/dcl list rbegin | vector}}
{{dcl list template | cpp/container/dcl list rend | vector}}
+
{{dsc inc | cpp/container/dcl list rend | vector}}
  
{{dcl list h2 | Capacity}}
+
{{dsc h2 | Capacity}}
{{dcl list template | cpp/container/dcl list empty | vector}}
+
{{dsc inc | cpp/container/dcl list empty | vector}}
{{dcl list template | cpp/container/dcl list size | vector}}
+
{{dsc inc | cpp/container/dcl list size | vector}}
{{dcl list template | cpp/container/dcl list max_size | vector}}
+
{{dsc inc | cpp/container/dcl list max_size | vector}}
{{dcl list template | cpp/container/dcl list reserve | vector}}
+
{{dsc inc | cpp/container/dcl list reserve | vector}}
{{dcl list template | cpp/container/dcl list capacity | vector}}
+
{{dsc inc | cpp/container/dcl list capacity | vector}}
  
{{dcl list h2 | Modifiers}}
+
{{dsc h2 | Modifiers}}
{{dcl list template | cpp/container/dcl list clear | vector}}
+
{{dsc inc | cpp/container/dcl list clear | vector}}
{{dcl list template | cpp/container/dcl list insert | vector}}
+
{{dsc inc | cpp/container/dcl list insert | vector}}
{{dcl list template | cpp/container/dcl list erase | vector}}
+
{{dsc inc | cpp/container/dcl list erase | vector}}
{{dcl list template | cpp/container/dcl list push_back | vector}}
+
{{dsc inc | cpp/container/dcl list push_back | vector}}
{{dcl list template | cpp/container/dcl list pop_back | vector}}
+
{{dsc inc | cpp/container/dcl list pop_back | vector}}
{{dcl list template | cpp/container/dcl list resize | vector}}
+
{{dsc inc | cpp/container/dcl list resize | vector}}
{{dcl list template | cpp/container/dcl list swap | vector}}
+
{{dsc inc | cpp/container/dcl list swap | vector}}
  
{{dcl list h2 | {{tt|vector<bool>}} specific modifiers}}
+
{{dsc h2 | {{tt|vector<bool>}} specific modifiers}}
{{dcl list template | cpp/container/vector_bool/dcl list flip}}
+
{{dsc inc | cpp/container/vector_bool/dcl list flip}}
{{dcl list template | cpp/container/vector_bool/dcl list swap}}
+
{{dsc inc | cpp/container/vector_bool/dcl list swap}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Non-member functions===
 
===Non-member functions===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/container/dcl list operator_cmp | vector}}
+
{{dsc inc | cpp/container/dcl list operator_cmp | vector}}
{{dcl list template | cpp/container/dcl list swap2 | vector}}
+
{{dsc inc | cpp/container/dcl list swap2 | vector}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Helper classes===
 
===Helper classes===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/container/vector_bool/dcl list hash}}
+
{{dsc inc | cpp/container/vector_bool/dcl list hash}}
{{dcl list end}}
+
{{dsc end}}
  
 
===Notes===
 
===Notes===
If the size of the bitset is known at compile time, {{c|std::bitset}} may be used, which offers a richer set of member functions. In addition, [http://www.boost.org/doc/libs/release/libs/dynamic_bitset/dynamic_bitset.html boost::dynamic_bitset] exists as an alternative to {{tt|std::vector<bool>}}.
+
If the size of the bitset is known at compile time, {{lc|std::bitset}} may be used, which offers a richer set of member functions. In addition, [http://www.boost.org/doc/libs/release/libs/dynamic_bitset/dynamic_bitset.html boost::dynamic_bitset] exists as an alternative to {{tt|std::vector<bool>}}.
  
Since its representation may by optimized, {{c|std::vector<bool>}} does not necessarily meet all {{concept|Container}} or {{concept|SequenceContainer}} requirements. For example, because {{c|std::vector<bool>::iterator}} is implementation-defined, it may not satisfy the {{concept|ForwardIterator}} requirement.  Use of algorithms such as {{c|std::search}} that require {{concept|ForwardIterator}}s may result in [http://www.boost.org/doc/libs/1_52_0/libs/dynamic_bitset/dynamic_bitset.html#rationale either compile-time or run-time errors].
+
Since its representation may by optimized, {{c|std::vector<bool>}} does not necessarily meet all {{concept|Container}} or {{concept|SequenceContainer}} requirements. For example, because {{c|std::vector<bool>::iterator}} is implementation-defined, it may not satisfy the {{concept|ForwardIterator}} requirement.  Use of algorithms such as {{lc|std::search}} that require {{concept|ForwardIterator}}s may result in [http://www.boost.org/doc/libs/1_52_0/libs/dynamic_bitset/dynamic_bitset.html#rationale either compile-time or run-time errors].
  
 
[[de:cpp/container/vector bool]]
 
[[de:cpp/container/vector bool]]

Revision as of 18:41, 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

Template:cpp/container/dcl list value typeTemplate:cpp/container/dcl list allocator typeTemplate:cpp/container/dcl list size typeTemplate:cpp/container/dcl list difference typeTemplate:cpp/container/dcl list const referenceTemplate:cpp/container/dcl list pointerTemplate:cpp/container/dcl list const pointerTemplate:cpp/container/dcl list iteratorTemplate:cpp/container/dcl list const iteratorTemplate:cpp/container/dcl list reverse iteratorTemplate:cpp/container/dcl list const reverse iterator
Member type Definition
proxy class representing a reference to a single bool
(class)

Member functions

Template:cpp/container/dcl list constructorTemplate:cpp/container/dcl list destructorTemplate:cpp/container/dcl list operator=Template:cpp/container/dcl list assignTemplate:cpp/container/dcl list get allocatorTemplate:cpp/container/dcl list atTemplate:cpp/container/dcl list operator atTemplate:cpp/container/dcl list frontTemplate:cpp/container/dcl list backTemplate:cpp/container/dcl list beginTemplate:cpp/container/dcl list endTemplate:cpp/container/dcl list rbeginTemplate:cpp/container/dcl list rendTemplate:cpp/container/dcl list emptyTemplate:cpp/container/dcl list sizeTemplate:cpp/container/dcl list max sizeTemplate:cpp/container/dcl list reserveTemplate:cpp/container/dcl list capacityTemplate:cpp/container/dcl list clearTemplate:cpp/container/dcl list insertTemplate:cpp/container/dcl list eraseTemplate:cpp/container/dcl list push backTemplate:cpp/container/dcl list pop backTemplate:cpp/container/dcl list resizeTemplate:cpp/container/dcl list swapTemplate:cpp/container/vector bool/dcl list flipTemplate:cpp/container/vector bool/dcl list swap
Element access
Iterators
Capacity
Modifiers
vector<bool> specific modifiers

Non-member functions

Template:cpp/container/dcl list operator cmpTemplate:cpp/container/dcl list swap2

Helper classes

Template:cpp/container/vector bool/dcl list hash

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.