std::scoped_allocator_adaptor
ヘッダ <scoped_allocator> で定義
|
||
template< class OuterAlloc, class... InnerAlloc > class scoped_allocator_adaptor : public OuterAlloc; |
(C++11以上) | |
std::scoped_allocator_adaptor
クラステンプレートは多段コンテナ (マップのタプルのリストのセットのベクタ、など) で使用できるアロケータです。 1個の外側のアロケータ型 OuterAlloc
および0個以上の内側のアロケータ型 InnerAlloc...
を用いて実体化されます。 scoped_allocator_adaptor
を用いて直接構築されたコンテナは要素を確��するために OuterAlloc
を使用しますが、要素は、それ自身がコンテナであれば、最初の内側のアロケータを使用します。 そのコンテナの要素は、それ自身がコンテナであれば、2番目の内側のアロケータを使用します。 以下同様です。 内側のアロケータより多くの段数のコンテナが存在する場合、以降のすべてのネストしたコンテナは最後の内側のアロケータを再使用します。
このアダプタの目的は、ネストしたコンテナのすべての段が同じ共有メモリセグメントに配置しなければならないときなどに、ネストしたコンテナのステートフルなアロケータを正しく初期化することです。 アダプタのコンストラクタはリスト内のすべてのアロケータに対する引数を取り、ネストしたコンテナはそれぞれ必要に応じてアダプタからアロケータの状態を取得します。
scoped_allocator_adaptor
の目的において、次の内側のアロケータが A
の場合、 std::uses_allocator<T,A>::value == true である任意のクラス T
はそれがコンテナであるかのように再帰に参加します。 さらに、 scoped_allocator_adaptor::construct の特定のオーバーロードによって、 std::pair はそのようなコンテナとして扱われます。
一般的な実装はメンバオブジェクトとして std::scoped_allocator_adaptor<InnerAllocs...>
のインスタンスを保持します。
目次 |
[編集] メンバ型
型 | 定義 |
outer_allocator_type
|
OuterAlloc |
inner_allocator_type
|
scoped_allocator_adaptor<InnerAllocs...>、または sizeof...(InnerAllocs) == 0 の場合は scoped_allocator_adaptor<OuterAlloc> |
value_type
|
std::allocator_traits<OuterAlloc>::value_type |
size_type
|
std::allocator_traits<OuterAlloc>::size_type |
difference_type
|
std::allocator_traits<OuterAlloc>::difference_type |
pointer
|
std::allocator_traits<OuterAlloc>::pointer |
const_pointer
|
std::allocator_traits<OuterAlloc>::const_pointer |
void_pointer
|
std::allocator_traits<OuterAlloc>::void_pointer |
const_void_pointer
|
std::allocator_traits<OuterAlloc>::const_void_pointer |
propagate_on_container_copy_assignment
| |
propagate_on_container_move_assignment
| |
propagate_on_container_swap
| |
is_always_equal (C++17)
| |
rebind
|
[編集] メンバ関数
新しい scoped_allocator_adaptor のインスタンスを作成します (パブリックメンバ関数) | |
scoped_allocator_adaptor のインスタンスを破棄します (パブリックメンバ関数) | |
scoped_allocator_adaptor を代入します (パブリックメンバ関数) | |
inner_allocator の参照を取得します (パブリックメンバ関数) | |
outer_allocator の参照を取得します (パブリックメンバ関数) | |
外側のアロケータを使用して未初期化記憶域を確保します (パブリックメンバ関数) | |
外側のアロケータを使用して記憶域を解放します (パブリックメンバ関数) | |
外側のアロケータによってサポートされる最大確保サイズを返します (パブリックメンバ関数) | |
適切であればコンストラクタに内側のアロケータを渡して、確保された記憶域内にオブジェクトを構築します (パブリックメンバ関数) | |
確保された記憶域内のオブジェクトを破棄します (パブリックメンバ関数) | |
scoped_allocator_adaptor およびそのすべてのアロケータの状態をコピーします (パブリックメンバ関数) |
[編集] 非メンバ関数
(C++20で削除) |
2つの scoped_allocator_adaptor のインスタンスを比較します (パブリックメンバ関数) |
[編集] 推定ガイド(C++17以上)
[編集] 例
#include <vector> #include <scoped_allocator> #include <boost/interprocess/managed_shared_memory.hpp> #include <boost/interprocess/allocators/adaptive_pool.hpp> namespace bi = boost::interprocess; template<class T> using alloc = bi::adaptive_pool<T, bi::managed_shared_memory::segment_manager>; using ipc_row = std::vector<int, alloc<int>>; using ipc_matrix = std::vector<ipc_row, std::scoped_allocator_adaptor<alloc<ipc_row>>>; int main () { bi::managed_shared_memory s(bi::create_only, "Demo", 65536); // create vector of vectors in shared memory ipc_matrix v(s.get_segment_manager()); // for all these additions, the inner vectors obtain their allocator arguments // from the outer vector's scoped_allocator_adaptor v.resize(1); v[0].push_back(1); v.emplace_back(2); std::vector<int> local_row = {1,2,3}; v.emplace_back(local_row.begin(), local_row.end()); bi::shared_memory_object::remove("Demo"); }
[編集] 関連項目
(C++11) |
アロケータ型に関する情報を提供します (クラステンプレート) |
(C++11) |
指定された型がアロケータ使用構築をサポートしているかどうか調べます (クラステンプレート) |
デフォルトのアロケータ (クラステンプレート) |