< cpp‎ | memory
Dynamic memory management
Uninitialized storage
(until C++20)
Garbage collection support
C Library
Low level memory management
Defined in header <memory>
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)
(removed in C++20)

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 the requirements of LegacyOutputIterator 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.

Type requirements

OutputIt must meet the requirements of LegacyOutputIterator.

Member functions

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

Member types

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

These member types are required to be obtained by inheriting from std::iterator<std::output_iterator_tag, void, void, void, void>.

(until 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';
    std::allocator<std::string>().deallocate(p, 5);



See also

provides information about allocator types
(class template)
implements multi-level allocator for multi-level containers
(class template)
checks if the specified type supports uses-allocator construction
(class template)