Namespaces
Variants
Views
Actions

std::raw_storage_iterator

From cppreference.com
< cpp‎ | memory
Revision as of 15:38, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <memory>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
template< class OutputIt, class T >

class raw_storage_iterator

    : public std::iterator<std::output_iterator_tag, void, void, void, void>;
</td>

<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 OutputIt is any type that meets thee requirements of OutputIterator and has operator* defined to return an object, for which operator& returns an object of type T*. Usually, the type T* is used as OutputIt.

Contents

Type requirements

-
OutputIt must meet the requirements of 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)

Inherited from std::iterator

Member types

Member type Definition
value_type void
difference_type void
pointer void
reference void
iterator_category std::output_iterator_tag

Example

#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);
}

Output:

This
is
a
test
.

See also

Template:cpp/memory/dcl list allocator traitsTemplate:cpp/memory/dcl list scoped allocator adaptorTemplate:cpp/memory/dcl list uses allocator