std::raw_storage_iterator

定义于头文件 <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 起)
(弃用)

输出迭代器 std::raw_storage_iterator 使得标准算法能存储结果于未初始化内存。凡在算法写 T 类型对象到解引用后的迭代器时,对象被复制构造到该迭代器所指向的未初始化存储中的位置。模板形参 OutputIt 是任何满足输出迭代器 (OutputIterator) 要求的类型,并拥有定义为返回对象的 operator*operator& 对该对象返回 T* 类型值。通常,以类型 T*OutputIt

目录

类型要求

-
OutputIt 必须满足 OutputIterator 的要求。

成员函数

创建新的 raw_storage_iterator
(公开成员函数)
在缓冲区中的被指向位置构造对象
(公开成员函数)
解引用迭代器
(公开成员函数)
推进迭代器
(公开成员函数)
(C++17 起)
提供到被包装迭代器的访问
(公开成员函数)

成员类型

成员类型 定义
value_type void
difference_type void
pointer void
reference void
iterator_category std::output_iterator_tag

注意:在 C++17 前,这些成员类型要求通过从 std::iterator<std::output_iterator_tag,void,void,void,void> 继承而获得。

示例

#include <iostream>
#include <string>
#include <memory>
#include <algorithm>
 
int main()
{
    const std::string s[] = {"This", "is", "a", "test", "."};
    std::string* p = std::get_temporary_buffer<std::string>(5).first;
 
    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::return_temporary_buffer(p);
}

输出:

This
is
a
test
.

参阅

提供关于分配器类型的信息
(类模板)
为多级容器实现的多级分配器
(类模板)
检查指定的类型是否支持使用分配器的构造
(类模板)

版本历史

  • (当前 | 先前 2017年9月12日 (二) 06:46Fruderica讨论 | 贡献. . (2,281字节) (-1,080). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 17:56P12bot讨论 | 贡献 . . (3,361字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:05P12bot讨论 | 贡献 . . (3,361字节) (-135). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 15:39P12bot讨论 | 贡献 . . (3,496字节) (+313). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 03:39P12讨论 | 贡献 . . (3,183字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (3,183字节) (-52). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:10P12讨论 | 贡献 . . (3,235字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (3,235字节) (+3,235). . (Translated from the English version using Google Translate)