名前空間
変種
操作

std::raw_storage_iterator

提供: cppreference.com
< cpp‎ | memory
 
 
動的メモリ管理
スマートポインタ
(C++11)
(C++11)
(C++11)
(C++17未満)
(C++11)
アロケータ
メモリリソース
未初期化記憶域
raw_storage_iterator
(C++20未満)
ガベージコレクションサポート
その他
(C++20)
(C++11)
(C++11)
C のライブラリ
低水準のメモリ管理
 
 
ヘッダ <memory> で定義
template< class OutputIt, class T >

class raw_storage_iterator

    : public std::iterator<std::output_iterator_tag, void, void, void, void>;
(C++17未満)
template< class OutputIt, class T >
class raw_storage_iterator;
(C++17以上)
(非推奨)
(C++20で削除)

出力イテレータ std::raw_storage_iterator は標準アルゴリズムが未初期化メモリに結果を格納できるようにします。 アルゴリズムが逆参照したイテレータに T 型のオブジェクトを書き込むとき、オブジェクトはイテレータの指す未初期化記憶域の位置にコピー構築されます。 テンプレート引数 OutputIt は、 LegacyOutputIterator を満たし、 T* 型のオブジェクトを返す operator& を持つオブジェクトを返す operator* を持つ、任意の型です。 通常、型 T*OutputIt として使用されます。

目次

[編集] 型の要件

-
OutputItLegacyOutputIterator の要件を満たさなければなりません。

[編集] メンバ関数

新しい raw_storage_iterator を作成します
(パブリックメンバ関数) [edit]
バッファ内の指す先の位置にオブジェクトを構築します
(パブリックメンバ関数) [edit]
イテレータを逆参照します
(パブリックメンバ関数) [edit]
イテレータを進めます
(パブリックメンバ関数) [edit]
(C++17以上)
ラップされたイテレータへのアクセスを提供します
(パブリックメンバ関数) [edit]

[編集] メンバ型

メンバ型 定義
iterator_category std::output_iterator_tag
value_type void
difference_type void
pointer void
reference void

メンバ型 iterator_categoryvalue_typedifference_typepointer および referencestd::iterator<std::output_iterator_tag, void, void, void, void> から継承することによって取得することが要求されます。

(C++17未満)

[編集]

#include <iostream>
#include <string>
#include <memory>
#include <algorithm>
 
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
.

[編集] 関連項目

アロケータ型に関する情報を提供します
(クラステンプレート) [edit]
多段コンテナのための多段アロケータを実装します
(クラステンプレート) [edit]
指定された型がアロケータ使用構築をサポートしているかどうか調べます
(クラステンプレート) [edit]