std:: scoped_allocator_adaptor
|
ヘッダーで定義
<scoped_allocator>
|
||
|
template
<
class
OuterAlloc,
class
...
class
scoped_allocator_adaptor
|
(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
は、あたかもコンテナであるかのように再帰に参加します。さらに、
std::pair
は、
scoped_allocator_adaptor::construct
の特定のオーバーロードによって、そのようなコンテナとして扱われます。
典型的な実装では、メンバーオブジェクトとして
std::scoped_allocator_adaptor<InnerAllocs...>
のインスタンスを保持します。
std::pmr::polymorphic_allocator
s
がネストされたコンテナに伝播する際は
uses-allocator construction
に従い、
std::scoped_allocator_adaptor
は必要とせず(また動作しません)ことに注意してください。
目次 |
ネストされた型
| 型 | 定義 |
outer_allocator_type
|
OuterAlloc
|
inner_allocator_type
|
|
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 |
与えられた
OuterAlloc
と
InnerAlloc...
のセットを
Allocs
として:
| 型 | 定義 |
propagate_on_container_copy_assignment
|
|
propagate_on_container_move_assignment
|
|
propagate_on_container_swap
|
|
is_always_equal
|
|
メンバー関数
scoped_allocator_adaptor
オブジェクトを新規作成
(public member function) |
|
scoped_allocator_adaptor
オブジェクトを破棄
(public member function) |
|
scoped_allocator_adaptor
を代入
(public member function) |
|
inner_allocator
の参照を取得
(public member function) |
|
outer_allocator
の参照を取得
(public member function) |
|
|
外部アロケータを使用して未初期化ストレージを割り当て
(public member function) |
|
|
外部アロケータを使用してストレージを解放
(public member function) |
|
|
外部アロケータがサポートする最大割り当てサイズを返却
(public member function) |
|
|
割り当て済みストレージ内でオブジェクトを構築(適切な場合には内部アロケータをコンストラクタに渡す)
(public member function) |
|
|
割り当て済みストレージ内のオブジェクトを破棄
(public member function) |
|
scoped_allocator_adaptor
と全てのアロケータの状態をコピー
(public member function) |
|
説明専用関数テンプレート |
|
|
最外部アロケータを取得
( 説明専用メンバ関数* ) |
|
|
最外部アロケータを使用してオブジェクトを構築
( 説明専用メンバ関数* ) |
|
|
最外部アロケータを使用してオブジェクトを破棄
( 説明専用メンバ関数* ) |
|
非メンバー関数
|
(C++20で削除)
|
二つの
scoped_allocator_adaptor
オブジェクトを比較する
(関数テンプレート) |
推論ガイド (C++17以降)
ネストされたクラス
| クラス | 定義 |
rebind
|
template
<
class
T
>
struct
rebind
|
例
#include <boost/interprocess/allocators/adaptive_pool.hpp> #include <boost/interprocess/managed_shared_memory.hpp> #include <scoped_allocator> #include <vector> 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); // 共有メモリ内でのベクトルのベクトルを作成 ipc_matrix v(s.get_segment_manager()); // これらの追加操作では、内部ベクトルはそのアロケータ引数を // 外部ベクトルの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++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2108 | C++11 |
scoped_allocator_adaptor
がステートレスかどうかを示す方法がなかった
|
is_always_equal
を提供
|
関連項目
|
(C++11)
|
アロケータ型に関する情報を提供する
(クラステンプレート) |
|
(C++11)
|
指定された型がuses-allocator構築をサポートするかチェックする
(クラステンプレート) |
|
デフォルトアロケータ
(クラステンプレート) |