Difference between revisions of "cpp/container/vector bool"
(added std::hash link) |
(an) |
||
Line 87: | Line 87: | ||
===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, {{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>}}. | ||
+ | |||
+ | {{c|std::vector<bool>}} does not not fulfill all container requirements because of proxy class {{c|std::vector<bool>::reference}}. Because of this proxy reference, the {{c|std::vector<bool>::iterator}} cannot be a {{concept|ForwardIterator}}. Therefore this iterator does not fulfill the {{concept|ForwardIterator}} requirement of some algorithms as for {{c|std::search}}. Consequently, this misuse can cause many problems... Moreover, depending on the implementation, they may not be a compile error or even a run-time error! (reference: [http://www.boost.org/doc/libs/1_52_0/libs/dynamic_bitset/dynamic_bitset.html#rationale boost]) | ||
[[de:cpp/container/vector bool]] | [[de:cpp/container/vector bool]] |
Revision as of 05:27, 8 January 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 functions
Non-member functions
Helper classes
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>
.
std::vector<bool> does not not fulfill all container requirements because of proxy class std::vector<bool>::reference. Because of this proxy reference, the std::vector<bool>::iterator cannot be a Template:concept. Therefore this iterator does not fulfill the Template:concept requirement of some algorithms as for std::search. Consequently, this misuse can cause many problems... Moreover, depending on the implementation, they may not be a compile error or even a run-time error! (reference: boost)