◐ Shell
clean mode source ↗

std::raw_storage_iterator - cppreference.com

提供: cppreference.com

<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>

ヘッダ <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 として使用されます。

型の要件

メンバ関数

メンバ型

メンバ型 定義
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);
}

出力:

関連項目