Difference between revisions of "cpp/memory/raw storage iterator"
(→Example: fmt) |
(fix memory leak in the example (oops)) |
||
Line 35: | Line 35: | ||
const std::string s[] = {"This", "is", "a", "test", "."}; | const std::string s[] = {"This", "is", "a", "test", "."}; | ||
std::string* p = std::get_temporary_buffer<std::string>(5).first; | std::string* p = std::get_temporary_buffer<std::string>(5).first; | ||
+ | |||
std::copy(std::begin(s), std::end(s), | std::copy(std::begin(s), std::end(s), | ||
std::raw_storage_iterator<std::string*, std::string>(p)); | std::raw_storage_iterator<std::string*, std::string>(p)); | ||
− | for(std::string* i = p; i!=p+5; ++i) | + | |
− | + | for(std::string* i = p; i!=p+5; ++i) { | |
+ | std::cout << *i << '\n'; | ||
+ | i->~basic_string<char>(); | ||
+ | } | ||
std::return_temporary_buffer(p); | std::return_temporary_buffer(p); | ||
} | } |
Revision as of 09:36, 8 December 2011
Template:cpp/memory/allocator/sidebar Template:ddcl list begin <tr class="t-dsc-header">
<td><memory>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td class="t-dcl-nopad">class raw_storage_iterator
<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end
The output iterator std::raw_storage_iterator
makes it possible for standard algorithms to store results in uninitialized memory. Whenever the algorithm writes an object of type T
to the dereferenced iterator, the object is copy-constructed into the location in the uninitialized storage pointed to by the iterator. The template parameter OutputIterator
is any type that satisfied output iterator requirements and has Template:cpp defined to return an object, for which Template:cpp returns an object of type T*
. Usually, the type T*
is used as OutputIterator
.
Member functions
creates a new raw_storage_iterator (public member function) | |
returns a reference to this raw_storage_iterator (public member function) | |
copy-constructs an object at the pointed-to location in the buffer (public member function) | |
advances the iterator (public member function) |
This section is incomplete Reason: inherited from std::iterator |