Skip to content
Go to file
Cannot retrieve contributors at this time
77 lines (56 sloc) 3.12 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Extending raw_storage_iterator</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
LEWG, SG14: D0039R0
<BR>Brent Friedman
<H1>Extending raw_storage_iterator</H1>
<H2>I. Motivation</H2>
<p>Management of uninitialized memory is an important topic for those implementing containers, allocators, and similar library facilities. This paper seeks to modernize raw storage iterator, bringing important missing features to this utility class.</p>
<H2>II. Summary</H2>
<H3>Move construction</H3>
<p>raw_storage_iterator lacks support for move construction of elements. Currently users will be faced with the surprising behavior of copy construction in all circumstances.
<blockquote><code>*it = std::move(x); //copy constructs using x</code></blockquote>
<H3>Factory function</H3>
<p>raw_storage_iterator requires two template parameters which make its usage fairly verbose. We propose a factory function similar to make_shared for improving readability and making its use less error prone.</p>
<H3>Placement new support</H3>
<p>The primary use of raw_storage_iterator is to serve as a helper for constructing objects in place. Despite this, it does not support placement new syntax. Support for placement new into a raw storage iterator makes this iterator useful in new contexts.</p>
<H2>III. Discussion</H2>
<p>Comments at Lenexa stated that raw_storage_iterator is obscure and underused. Fixing these holes should at least open room for this class to be utilized more frequently and to exhibit expected behavior.</p>
<p>No facilities are provided for conditional move, as with move_if_noexcept. The structure of this class would require an understanding of move_if_noexcept to be built-in to the type system and so seems to have no good avenue for pursuit. Users of raw_storage_iterator should use move_if_noexcept at the callsite as they would with any other iterator:<br>
*it = move_if_noexcept(v);
<H2>IV. Proposed Text</H2>
<p>Make the following changes in [storage.iterator]: <br>
template&lt;class T&gt;
auto make_storage_iterator( T&& iterator)
return raw_storage_iterator&lt;std::remove_reference&lt;T&gt;::type, decltype(*iterator)&gt;( std::forward&lt;T&gt;(iterator));
template&lt;class T, class U&gt;
void* operator new(size_t s, raw_storage_iterator&lt;T,U&gt; it) noexcept
return ::operator new(s, it.base() );
template&lt;class T, class U&gt;
void operator delete ( void* m, raw_storage_iterator&lt;T,U&gt; it) noexcept
return ::operator delete(m, it.base() );
<p>Add to raw_storage_iterator:
raw_storage_iterator& operator=(T&& element);
<b>Effects:</b> Move-constructs a value from element at the location to which the iterator points.<br>
<b>Returns:</b> A reference to the iterator.
<p>Amend operator=(const T& element) as follows:</p>
<p>Effects: <u>Copy-c</u>onstructs a value from element ... </p>
You can’t perform that action at this time.