名前空間
変種
操作

std::vector<bool>

提供: cppreference.com
< cpp‎ | container
 
 
 
 
ヘッダ <vector> で定義
template<class Allocator>
class vector<bool, Allocator>;

std::vector<bool>bool 型に対する std::vector の空間効率の良い特殊化です。

std::vector<bool> がどのように空間効率を高めているのか (また、そもそも最適化自体しているのかどうか) は処理系定義です。 有り得る最適化としては、各要素が sizeof(bool) バイトではなく1ビットしか占めないようにベクタの要素を詰め込むといったことが考えられます。

std::vector<bool>std::vector と同様に振る舞いますが、空間効率のため、以下の点が異なります。

  • 要素が隣接した配列として格納されるとは限りません (&v[0]+ n !=&v[n])
  • 個々のビットにアクセスする方法としてのクラス std::vector<bool>::reference が露出します。 特に operator[] の戻り値としてこのクラスのオブジェクトが値返しされます。
  • ビット値を構築するために std::allocator_traits::construct を使用しません。
  • 同じコンテナの異なる要素を異なるスレッドから並行的に変更できる保証がありません。

目次

[編集]メンバ型

メンバ型 定義
value_typebool[edit]
allocator_typeAllocator[edit]
size_type 処理系定義 [edit]
difference_type 処理系定義[edit]
1個の bool への参照を表すプロキシクラス
(クラス)
const_referencebool[edit]
pointer 処理系定義[edit]
const_pointer 処理系定義[edit]
iterator 処理系定義 [edit]
const_iterator 処理系定義 [edit]
reverse_iteratorstd::reverse_iterator<iterator>[edit]
const_reverse_iteratorstd::reverse_iterator<const_iterator>[edit]

[編集]メンバ関数

vector を構築します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
vector を破棄します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
コンテナに値を代入します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
コンテナに値を代入します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
関連付けられているアロケータを返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
要素アクセス
境界チェック付きで指定された要素にアクセスします
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
指定された要素にアクセスします
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
最初の要素にアクセスします
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
最後の要素にアクセスします
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
イテレータ
先頭を指すイテレータを返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
終端を指すイテレータを返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
先頭を指す逆イテレータを返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
終端を指す逆イテレータを返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
容量
コンテナが空かどうか調べます
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
要素数を返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
可能な最大の要素数を返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
記憶域を予約します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
現在確保されている記憶域に保持できる要素の数を返します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
変更
すべての要素を削除します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
要素を挿入します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
(C++14)
要素を直接構築します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
要素を削除します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
要素を末尾に追加します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
要素を末尾に直接構築します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
最後の要素を削除します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
格納されている要素の数を変更します
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
(C++11)
内容を入れ替えます
(std::vector<T,Allocator>のパブリックメンバ関数)[edit]
vector<bool> 固有の関数
すべてのビットを反転します
(パブリックメンバ関数)[edit]
[静的]
2つの std::vector<bool>::reference を入れ替えます
(パブリック静的メンバ関数)[edit]

[編集]非メンバ関数

(C++20で削除)(C++20で削除)(C++20で削除)(C++20で削除)(C++20で削除)(C++20)
vector 内の値を辞書的に比較します
(関数テンプレート)[edit]
std::swap アルゴリズムの特殊化
(関数テンプレート)[edit]

[編集]ヘルパークラス

std::vector<bool> に対するハッシュサポート
(クラステンプレートの特殊化)[edit]

[編集]ノート

ビット集合のサイズがコンパイル時に判明している場合は、よりリッチなメンバ関数のセットを提供する std::bitset を使用することができます。 さらに、 std::vector<bool> の代替として boost::dynamic_bitset もあります。

表現が最適化される可能性があるため、 std::vector<bool>Container または SequenceContainer のすべての要件を満たすとは限りません。 例えば、 std::vector<bool>::iterator は処理系定義であるため、 LegacyForwardIterator の要件を満たさないかもしれません。 std::search のような LegacyForwardIterator を要求するアルゴリズムの使用は、コンパイル時または実行時のエラーになるかもしれません。

vector の Boost.Container バージョンbool に対して特殊化しません。

close