std::raw_storage_iterator
From cppreference.com
| ヘッダ <memory> で定義 |
||
| template< class OutputIt, class T > class raw_storage_iterator |
(C++17まで) | |
| template< class OutputIt, class T > class raw_storage_iterator; |
(C++17以降) (C++17で非推奨) (C++20で削除) |
|
出力イテレータ std::raw_storage_iterator は、標準アルゴリズムが初期化されていないメモリに結果を保存することを可能にします。アルゴリズムが型 T のオブジェクトをデリファレンスされたイテレータに書き込むたびに、そのオブジェクトはイテレータが指す初期化されていないストレージ内の場所にコピー構築されます。テンプレートパラメータ OutputIt は、LegacyOutputIterator の要件を満たし、operator* がオブジェクトを返すように定義されており、そのオブジェクトに対して operator& が型 T* のオブジェクトを返す任意の型です。通常、型 T* が OutputIt として使用されます。
目次 |
[編集] 型要件
-OutputIt は LegacyOutputIterator の要件を満たさなければなりません。 |
[編集] メンバ関数
新しい raw_storage_iterator を作成する(public メンバ関数) | |
| バッファ内の指された場所にオブジェクトを構築する (public メンバ関数) | |
| イテレータをデリファレンスする (public メンバ関数) | |
| イテレータを進める (public メンバ関数) | |
| (C++17以降) |
ラップされたイテレータへのアクセスを提供する (public メンバ関数) |
[編集] メンバ型
| メンバ型 | 定義 | ||||
iterator_category
|
std::output_iterator_tag | ||||
value_type
|
void | ||||
difference_type
|
| ||||
pointer
|
void | ||||
reference
|
void |
|
メンバ型 |
(C++17まで) |
[編集] 注意
std::raw_storage_iterator は、主に例外安全でない振る舞いのため非推奨となりました。std::uninitialized_copy とは異なり、std::copy のような操作中に例外を安全に処理せず、構築されたオブジェクトの数や例外発生時の適切な破棄を追跡しないため、リソースリークにつながる可能性があります。
[編集] 例
このコードを実行
#include <algorithm> #include <iostream> #include <memory> #include <string> int main() { const std::string s[] = {"This", "is", "a", "test", "."}; std::string* p = std::allocator<std::string>().allocate(5); std::copy(std::begin(s), std::end(s), std::raw_storage_iterator<std::string*, std::string>(p)); for (std::string* i = p; i != p + 5; ++i) { std::cout << *i << '\n'; i->~basic_string<char>(); } std::allocator<std::string>().deallocate(p, 5); }
出力
This is a test .
[編集] 関連項目
| (C++11) |
アロケータ型に関する情報を提供します (クラステンプレート) |
| (C++11) |
多階層コンテナのための多階層アロケータを実装します (クラステンプレート) |
| (C++11) |
指定された型が uses-allocator 構築をサポートしているかどうかをチェックします (クラステンプレート) |