在线文档教程
C++
动态内存管理 | Dynamic memory management

std::raw_storage_iterator

性病:生[医]储物[医]迭代器

Defined in header
template< class OutputIt, class T > class raw_storage_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void>;(until C++17)
template< class OutputIt, class T > class raw_storage_iterator;(since C++17) (deprecated)

输出迭代器std::raw_storage_iterator使标准算法能够将结果存储在未初始化的内存中。每当算法写入类型的对象时T对于取消引用的迭代器,对象被复制到迭代器所指向的未初始化存储中的位置。模板参数OutputIt是否符合OutputIterator而且有operator*定义为返回对象,其中operator&返回类型为T*.通常,类型T*被用作OutputIt...

类型要求

-输出必须符合输出器的要求。

*。

成员函数

(constructor)creates a new raw_storage_iterator (public member function)
operator=constructs an object at the pointed-to location in the buffer (public member function)
operator*dereferences the iterator (public member function)
operator++operator++(int)advances the iterator (public member function)
base (since C++17)provides access to the wrapped iterator (public member function)

成员类型

Member typeDefinition
value_typevoid
difference_typevoid
pointervoid
referencevoid
iterator_categorystd::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 .

二次

另见

allocator_traits (C++11)provides information about allocator types (class template)
scoped_allocator_adaptor (C++11)implements multi-level allocator for multi-level containers (class template)
uses_allocator (C++11)checks if the specified type supports uses-allocator construction (class template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/Memory/RAW[医]储物[医]迭代器