<html>
<head>
<title>Impact of rvalue reference on the library</title>
<style>
p {text-align:justify}
li {text-align:justify}
blockquote.note {background-color:silver}
ins {color:red}
</style>
</head>

<body>

<address align=right>
Document number: N1771=05-0031<br>
<br>
<a href="mailto:dave@boost-consulting.com">David Abrahams</a><br>
<a href="mailto:pdimov@mmltd.net">Peter Dimov</a><br>
<a href="mailto:dgregor@cs.indiana.edu">Doug Gregor</a><br>
<a href="mailto:hinnant@twcny.rr.com">Howard E. Hinnant</a><br>
<a href="mailto:hommel@metrowerks.com">Andreas Hommel</a><br>
<a href="mailto:wg21@alisdairm.net">Alisdair Meredith</a><br>
2005-03-03
</address>
<hr>

<h1 align=center>Impact of the rvalue reference on the Standard Library</h1>

<h2>Introduction</h2>

<p>
The purpose of this document is to survey and recommend changes to the standard
library (and anticipated library components) assuming that the <i>rvalue
reference</i> proposal documented by <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1377.htm">N1377</a>,
<a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1690.html">N1690</a>
and <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1770.html">N1770</a>
becomes part of the C++ language.
</p>

<p>
The remainder of this paper sweeps through the library chapters, and through
TR1, noting anticipated changes.  The paper does not provide proposed wording,
though some of the wording found below may approach proposed wording.
</p>

<h2>20.1 - Requirements</h2>

<h3>20.1.3 - Copy construction (and assignment)</h3>

<p>
It is anticipated that new requirements <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt> will be introduced, and contrasted with the current
<tt>CopyConstructible</tt> and <tt>Assignable</tt> requirements.  The
<tt>Swappable</tt> requirement is also introduced, brought in from the proposed
resolution of LWG issue 226 (<a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1523.htm">N1523</a>).
</p>

<p>
In the following Tables, <tt>T</tt> is a type to be supplied by a C++ program,
<tt>t</tt> and <tt>t1</tt> are lvalues of type <tt>T</tt>, <tt>rv</tt> is an
rvalue of type <tt>T</tt>, and <tt>u</tt> is a value (lvalue or rvalue) of type
<tt>const T</tt>.
</p>

<p><center>
<table border="1">
<caption><tt>MoveConstructible</tt> requirements</caption>
<tr><th>expression</th> <th>post-condition</th></tr>
<tr><td><tt>T(rv)</tt></td> <td><tt>T(rv)</tt> is equivalent to the value of <tt>rv</tt> before the construction</td></tr>
</table>
</center></p>

<p><center>
<table border="1">
<caption><tt>CopyConstructible</tt> requirements</caption>
<tr><th>expression</th> <th>post-condition</th></tr>
<tr><td><tt>T(rv)</tt></td> <td><tt>T(rv)</tt> is equivalent to the value of <tt>rv</tt> before the construction</td></tr>
<tr><td><tt>T(t)</tt></td> <td><tt>T(t)</tt> is equivalent to <tt>t</tt>, the value of <tt>t</tt> is not altered</td></tr>
<tr><td><tt>T(u)</tt></td> <td><tt>T(u)</tt> is equivalent to <tt>u</tt>, the value of <tt>u</tt> is not altered</td></tr>
</table>
</center></p>

<p>
[Footnote:  Note that a type that satisfies the <tt>CopyConstructible</tt>
requirements also satisfies the <tt>MoveConstructible</tt> requirements.]
</p>

<p><center>
<table border="1">
<caption><tt>MoveAssignable</tt> requirements</caption>
<tr><th>expression</th> <th>return type</th> <th>return value</th> <th>post-condition</th></tr>
<tr><td><tt>t = rv</tt></td> <td><tt>T&</tt></td> <td><tt>t</tt></td> <td><tt>t</tt> is equivalent to the value of <tt>rv</tt> before the assignment</td></tr>
</table>
</center></p>

<p><center>
<table border="1">
<caption><tt>CopyAssignable</tt> requirements</caption>
<tr><th>expression</th> <th>return type</th> <th>return value</th> <th>post-condition</th></tr>
<tr><td><tt>t = rv</tt></td> <td><tt>T&</tt></td> <td><tt>t</tt></td> <td><tt>t</tt> is equivalent to the value of <tt>rv</tt> before the assignment</td></tr>
<tr><td><tt>t = t1</tt></td> <td><tt>T&</tt></td> <td><tt>t</tt></td> <td><tt>t</tt> is equivalent to <tt>t1</tt>, the value of <tt>t1</tt> is not altered</td></tr>
<tr><td><tt>t = u</tt></td> <td><tt>T&</tt></td> <td><tt>t</tt></td> <td><tt>t</tt> is equivalent to <tt>u</tt>, the value of <tt>u</tt> is not altered</td></tr>
</table>
</center></p>

<p>
[Footnote:  Note that a type that satisfies the <tt>CopyAssignable</tt>
requirements also satisfies the <tt>MoveAssignable</tt> requirements.]
</p>

<p><center>
<table border="1">
<caption><tt>Swappable</tt> requirements</caption>
<tr><th>expression</th> <th>post-condition</th></tr>
<tr><td><tt>swap(t, u)</tt></td> <td><tt>t</tt> has the value originally held by <tt>u</tt>, and <tt>u</tt> has the value originally held by <tt>t</tt></td></tr>
</table>
</center></p>

<p>
The swappable requirement is met by satisfying one or more of the following
conditions:
</p>

<ul>
<li>
<tt>T</tt> is <tt>Swappable</tt> if <tt>T</tt> is <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt>.
</li>
<li>
<tt>T</tt> is <tt>Swappable</tt> if a namespace scope function named
<tt>swap</tt> exists in the same namespace as the definition of <tt>T</tt>, such
that the expression <tt>swap(t, u)</tt> is valid and has the semantics described
in Table??.
</li>
</ul>

<p>
[Footnote:  Note that a type that satisfies the <tt>CopyConstructible</tt> and
<tt>CopyAssignable</tt> requirements also satisfies the <tt>Swappable</tt>
requirements.]
</p>

<h3>20.1.5 - Allocator requirements</h3>

<p>
Add rows to the Descriptive variable definitions:
</p>

<p><center>
<table border="1">
<tr><td><tt>V</tt></td> <td>A type convertible to <tt>T</tt></td></tr>
<tr><td><tt>v</tt></td> <td>A value of type <tt>V</tt></td></tr>
</table>
</center></p>

<p>Add row to the requirements table:</p>

<p><center>
<table border="1">
<tr><td><tt>a.construct(p,v)</tt></td> <td>(not used)</td> <td>Effect: <tt>::new((void*)p) T(std::forward&lt;V&gt;(v))</tt></td></tr>
</table>
</center></p>

<p>
The new construct overload is typically implemented as a member template
function.  It obsoletes the current non-member template construct member, but
the current construct member is retained for binary backwards compatibility. The
new overload allows containers to move construct rvalues from single element
insert functions.  It also allows convertible types <tt>V</tt> to be used to
construct types <tt>T</tt>.  This is necessary (for example) in <tt>map</tt>
which must move construct a <tt>pair&lt;const key, value&gt;</tt> from an rvalue
<tt>pair&lt;key, value&gt;</tt>, because it is not possible to move from a
<tt>pair&lt;const key, value&gt;</tt>.
</p>

<p>
Allocators that are not move-aware, and don't meet this requirement will
continue to work in move-aware containers of types meeting the
<tt>CopyConstructible</tt> requirement.  But they will fail at compile time for
move-aware containers of types only meeting the <tt>MoveConstructible</tt>
requirement.  That is, if you want to put moveable but non-copyable types into a
move-aware container, the container's allocator must have this
<tt>construct</tt> overload.
</p>

<h2>20.2 - Utility components</h2>

<h3>synopsis</h3>

<p>Add:</p>

<blockquote><pre>
template &lt;class T&gt; struct identity {typedef T type;};
template &lt;class T&gt; T&& inline forward(typename identity&lt;T&gt;::type&& t)      {return t;}
template &lt;class T&gt; typename remove_reference&lt;T&gt;::type&& inline move(T&& t) {return t;}
</pre></blockquote>

<p>
These simply return their argument, and are used as helper functions in both
library and client code.
</p>

<p>
The <tt>move</tt> function's main job is to cast an lvalue to an rvalue.
<tt>move</tt> will always return an rvalue reference.  In contrast,
<tt>forward</tt> will not always return an rvalue reference, and the client
<i>must</i> specify the template argument.  <tt>forward</tt> will return an
lvalue reference if the specified template argument is an lvalue reference,
otherwise it will return an rvalue.  This behavior works in concert with the
template deduction rules for rvalue references to assure perfect forwarding.
</p>

<a name="old_move"></a><h4>Transition note for library vendors:</h4>

<p>
To support compilers which have not yet implemented the rvalue reference,
vendors can instead implement these as:
</p>

<blockquote><pre>
template &lt;class T&gt; struct identity {typedef T type;};
template &lt;class T&gt;
    T& inline forward(typename identity&lt;T&gt;::type& t) {return t;}
template &lt;class T&gt;
    T& inline move(T& t) {return t;}
template &lt;class T&gt;
    const T& inline move(const T& t) {return t;}
</pre></blockquote>

<p>
The functions won't move or forward when written this way, but their existence
will make it easier to write higher level code which uses <tt>move</tt> and
<tt>forward</tt>.  When ported to a compiler implementing the rvalue reference,
only the <tt>move</tt> and <tt>forward</tt> need be changed.  The (properly
written) higher level library code will work in either environment, but use copy
semantics (for example) in older compilers and use move semantics with the newer
compiler.  See example algorithm <a href="#insertion_sort">insertion_sort</a>.
</p>

<h3>20.2.2 - Pairs</h3>

<blockquote><pre>
template &lt;class T1, class T2&gt;
struct pair
{
    typedef T1 first_type;
    typedef T2 second_type;

    T1 first;
    T2 second;
    pair();
    pair(const T1& x, const T2& y);
    <b>template &lt;class U, class V&gt; pair(U&& x, V&& y);</b>
    <b>pair(pair&& p);</b>
    template &lt;class U, class V&gt; pair(const pair&lt;U, V&gt; &p);
    <b>template &lt;class U, class V&gt; pair(pair&lt;U, V&gt;&& p);</b>
    <b>pair& operator=(pair&& p);</b>
    <b>template &lt;class U, class V&gt; pair& operator=(pair&lt;U, V&gt;&& p);</b>
};
</pre></blockquote>

<p>
The intent is for the move constructor and move assignment of pair to forward
its arguments to T1 and T2's constructor and assignment as rvalues.  Also note
that movable but non-copyable types can now be put into pair (which in turn will
make pair movable but non-copyable).
</p>

<h3>20.4.1 - The default allocator</h3>

Add:

<blockquote><pre>
   template &lt;class U&gt; void construct(pointer p, U&& val);
</pre></blockquote>

<p>
Effects:  <tt>::new((void*)p) T(std::forward&lt;U&gt;(val))</tt>
</p>

<h3>20.4.5 - Class template auto_ptr</h3>

<p>Deprecate this section, but add <tt>unqiue_ptr</tt>:</p>

<blockquote><pre>
struct apply_delete
{
    template &lt;class T&gt;
    void operator() (T* ptr) {typedef char incomplete[sizeof(T)]; delete ptr;}
};

struct apply_array_delete
{
    template &lt;class T&gt;
    void operator() (T* ptr) {typedef char incomplete[sizeof(T)]; delete [] ptr;}
};

template &lt;class T, bool b = is_array&lt;T&gt;::value&gt;
struct default_delete
{
    typedef apply_delete type;
};

template &lt;class T&gt;
struct default_delete&lt;T, true&gt;
{
    typedef apply_array_delete type;
};

template&lt;class T, class D = typename default_delete&lt;T&gt;::type&gt;
class unique_ptr
{
public:
    typedef T element_type;
    typedef D deleter_type;

    unique_ptr();

    explicit unique_ptr(T* p);

    unique_ptr(T* p, const deleter_type& d);
    unique_ptr(T* p, deleter_type&& d);

    unique_ptr(unique_ptr&& a);
    template &lt;class U, class E&gt;
        unique_ptr(unique_ptr&lt;U, E>&& a);

    unique_ptr& operator=(unique_ptr&& a);

    template &lt;class U, class E&gt;
        unique_ptr& operator=(unique_ptr&lt;U, E&gt;&& a);

    ~unique_ptr();

    T& operator*() const;
    T* operator->() const;
    T* get() const;
    T* release();
    void reset(T* p = 0);
    void swap(unique_ptr&& a);
    deleter_type&       get_deleter();
    const deleter_type& get_deleter() const;

private: // express these in better standardeze
    struct bool_type {int dummy_;};
public:
    operator int bool_type::*() const;
    unique_ptr(int bool_type::*);
    unique_ptr& operator=(int bool_type::*);

private:
    // disable copy from lvalue
    unique_ptr(const unique_ptr& a);
        template &lt;class U, class E&gt; unique_ptr(const unique_ptr&lt;U, E&gt;& a);
    unique_ptr& operator=(const unique_ptr& a);
        template &lt;class U, class E&gt; unique_ptr& operator=(const unique_ptr&lt;U, E&gt;& a);
};

template&lt;class T, class D&gt;
class unique_ptr&lt;T[], D&gt;
{
public:
    typedef T element_type;
    typedef D deleter_type;

    unique_ptr();

    explicit unique_ptr(T*);
    unique_ptr(T* p, const deleter_type& d);
    unique_ptr(T* p, deleter_type&& d);

    unique_ptr(unique_ptr&& a);
    unique_ptr& operator=(unique_ptr&& a);

    ~unique_ptr();

    T& operator[](size_t i) const;
    T* get() const;
    T* release();
    void reset(T* p = 0);
    void swap(unique_ptr&& a);
    deleter_type&       get_deleter();
    const deleter_type& get_deleter() const;

private: // express these in better standardeze
    struct bool_type {int dummy_;};
public:
    operator int bool_type::*() const;
    unique_ptr(int bool_type::*);
    unique_ptr& operator=(int bool_type::*);

private:
    // disable copy from lvalue
    unique_ptr(const unique_ptr& a);
    unique_ptr& operator=(const unique_ptr& a);
};
</pre></blockquote>

<p>
<tt>unique_ptr</tt> really deserves (and will get) its own proposal.
Nevertheless, it is included here for completeness.  It is a very important
library component with respect to the rvalue reference and move semantics.
</p>

<p>
<tt>unique_ptr</tt> is an <tt>auto_ptr</tt> replacement that is not fully
backwards compatible.  Thus the need to deprecate <tt>auto_ptr</tt> and
introduce the new name (<tt>unique_ptr</tt>), instead of just fixing
<tt>auto_ptr</tt>.  The main similarities and differences between
<tt>unique_ptr</tt> and <tt>auto_ptr</tt> include:

</p>
<ul>
<li>
Moves with move syntax from lvalues, instead of copy syntax like
<tt>auto_ptr</tt>.  However it moves from rvalues with copy syntax just like
<tt>auto_ptr</tt>.
</li>
<li>
Unlike <tt>auto_ptr</tt>, refuses to move (or copy) from lvalues.  This is key
to safety in generic code.
</li>
<li>
You can return one from a function, with copy syntax as long as it is a local
auto variable, just like <tt>auto_ptr</tt>.
</li>
<li>
With the default deleter (and "empty" deleters), it can have the same overhead
(1 pointer) as <tt>auto_ptr</tt>.
</li>
<li>
The deleter can be a reference type.
</li>
<li>
The deleter can be "heavy weight", non-copyable and moved in.
</li>
<li>
With non-default deleters, other RAII functionality can be achieved.
</li>
<li>
There is a specialization to handle array forms.  The array form is more than
just a special deleter.  The interface is changed to one that is more
appropriate for arrays:
</li>
    <ul>
    <li>There is no operator*()</li>
    <li>There is no operator->()</li>
    <li>There is an operator[](size_t)</li>
    <li>No derived to base conversions are allowed</li>
    </ul>
<li>
Unlike <tt>auto_ptr</tt>, <tt>unique_ptr</tt> can be safely put into
(move-aware) containers.<br>[<i>Example:</i>
<blockquote><pre>
#include &lt;memory&gt;
#include &lt;vector&gt;

struct Base {virtual ~Base() {}};

struct Derived : Base {};

int main()
{
    typedef std::unique_ptr&lt;Base&gt;    BasePtr;
    typedef std::unique_ptr&lt;Derived&gt; DerivedPtr;
    std::vector&lt;BasePtr&gt; v(3);                   <font color="red">// 3 default constructed BasePtr's</font>
    v.resize(2);                                 <font color="red">// No copy constructor required</font>
    v.push_back(DerivedPtr(new Derived));        <font color="red">// No copy constructor required</font>
    v.front() = DerivedPtr(new Derived);         <font color="red">// No copy constructor required</font>
    v.insert(v.begin(), DerivedPtr(new Derived));<font color="red">// No copy constructor required</font>
    v.erase(v.begin() + v.size()/2);             <font color="red">// No copy constructor required</font>
//  BasePtr p = v[0];             <font color="red">// will not compile, copy constructor required</font>
    BasePtr p = std::move(v[0]);                 <font color="red">// ok, ownership transferred to p</font>
}
</pre></blockquote>
<i>--end example</i>]
</li>
</ul>

<h2>21 - Strings library</h2>

<p>
<b>Summary:</b>  Make string move constructible and move assignable.  Allow swap
to work with rvalues.  And allow string I/O to work with rvalue streams.
</p>

<p>Add to string synopsis:</p>

<blockquote><pre>
    basic_string(basic_string&& str);
    basic_string& operator=(basic_string&& str);
    basic_string& assign(basic_string&& str);
    void swap(basic_string<del>&</del><ins>&&</ins> str);
</pre></blockquote>

<p>And at namespace scope change/add:</p>

<blockquote><pre>
template &lt;class charT, class traits, class Allocator&gt;
     void swap(basic_string&lt;charT,traits,Allocator&gt;&& lhs,
               basic_string&lt;charT,traits,Allocator&gt;& rhs);

template &lt;class charT, class traits, class Allocator&gt;
     void swap(basic_string&lt;charT,traits,Allocator&gt;& lhs,
               basic_string&lt;charT,traits,Allocator&gt;&& rhs);

template &lt;class charT, class traits, class Allocator&gt;
   basic_ostream&lt;charT, traits&gt;&
    operator&gt;&gt;(basic_ostream&lt;charT, traits&gt;<del>&</del><ins>&&</ins> is,
               basic_string&lt;charT,traits,Allocator&gt;& str);
template &lt;class charT, class traits, class Allocator&gt;
  basic_ostream&lt;charT, traits&gt;&
    operator&lt;&lt;(basic_ostream&lt;charT, traits&gt;<del>&</del><ins>&&</ins> os,
               const basic_string&lt;charT,traits,Allocator&gt;& str);
template &lt;class charT, class traits, class Allocator&gt;
   basic_istream&lt;charT,traits&gt;&
     getline(basic_istream&lt;charT,traits&gt;<del>&</del><ins>&&</ins> is,
             basic_string&lt;charT,traits,Allocator&gt;& str,
             charT  delim);
template &lt;class charT, class traits, class Allocator&gt;
   basic_istream&lt;charT,traits&gt;&
     getline(basic_istream&lt;charT,traits&gt;<del>&</del><ins>&&</ins> is,
             basic_string&lt;charT,traits,Allocator&gt;& str);

template &lt;class charT, class traits, class Allocator&gt;
    basic_string&lt;charT,traits,Allocator&gt;&&
      operator+(basic_string&lt;charT,traits,Allocator&gt;&& lhs,
                const basic_string&lt;charT,traits,Allocator&gt;& rhs);
template &lt;class charT, class traits, class Allocator&gt;
    basic_string&lt;charT,traits,Allocator&gt;&&
      operator+(const basic_string&lt;charT,traits,Allocator&gt;& lhs,
                basic_string&lt;charT,traits,Allocator&gt;&& rhs);
template &lt;class charT, class traits, class Allocator&gt;
    basic_string&lt;charT,traits,Allocator&gt;&&
      operator+(basic_string&lt;charT,traits,Allocator&gt;&& lhs,
                basic_string&lt;charT,traits,Allocator&gt;&& rhs);
</pre></blockquote>

<h2>23 - Containers library</h2>

<p>
<b>Summary:</b>  Make all containers move constructible and move assignable.
Furthermore allow a subset of their functionality to work with movable but
non-copyable types (such as the proposed <tt>unique_ptr</tt>).
</p>

<h3>23.1 - Container requirements</h3>

<p>
-3- The type of objects stored in these components must meet the requirements of
<tt>MoveConstructible</tt> and <tt>MoveAssignable</tt> types.  Additionally for
some member functions (as noted below), the types must meet the requirements of
<tt>CopyConstructible</tt> and/or <tt>CopyAssignable</tt> types.  The copy
constructor of each container requires the contained element type to be
<tt>CopyConstructible</tt>.  The copy assignment operator of each sequence
container requires the contained type to be both <tt>CopyConstructible</tt> and
<tt>CopyAssignable</tt>.  The copy assignment operator of each associative
container requires the contained type to be <tt>CopyConstructible</tt>.
</p>

<p>
If the contained <tt>value_type</tt> alters the value of the source (even if the
source is an rvalue) when constructing or assigning, then the operation must not
throw an exception.
</p>

<p>
Delete 23.1p4 (assignable requirements).  This is now covered in 20.1.
</p>

<p>
Add two rows to the table of Container requirements in 23.1p5:
</p>

<p><center>
<table border="1">
<tr><td><tt>X(rv)</tt></td> <td>&nbsp;</td> <td>Equal to the value of rv before construction</td> <td>constant</td></tr>
<tr><td><tt>a = rv</tt></td> <td>&nbsp;</td> <td><tt>a</tt> is equal to the value of rv before assignment</td> <td>constant</td></tr>
</table>
</center></p>

<p>
The following synopsis of the containers has comments indicating those members
requiring stronger requirements than <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt>.  <tt>CC</tt> indicates <tt>CopyConstructible</tt> and
<tt>CA</tt> indicates <tt>CopyAssignable</tt>.  Those members not commented will
work for types supporting only <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt>.  New and modified functions are indicated in
<b>bold</b>.
</p>

<p>
Those members with a parameter of <tt>T&& x</tt> may assume that <tt>x</tt> is
not a reference into the container.
</p>

<h3>23.2.1 - Class template deque</h3>

<blockquote><pre>
template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
class deque {
public:
    //  types:
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef T                                     value_type;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    //  lib.deque.cons construct/copy/destroy:
    explicit deque(const Allocator& = Allocator());
    <b>explicit deque(size_type n);</b>  <font color="red">// Does not require CC</font>
    deque(size_type n, const T& value,
          const Allocator& = Allocator());  <font color="red">// CC</font>
    template &lt;class InputIterator&gt;
      deque(InputIterator first, InputIterator last,
            const Allocator& = Allocator());  <font color="red">// CC only if InputIterator returns lvalue</font>
    deque(const deque& x);  <font color="red">// CC</font>
    <b>deque(deque&& x);</b>
   ~deque();
    deque& operator=(const deque& x);  <font color="red">// CC and CA</font>
    <b>deque& operator=(deque&& x);</b>
    template &lt;class InputIterator&gt;
      void assign(InputIterator first,
                  InputIterator last);  <font color="red">// CC and CA only if InputIterator returns lvalue</font>
    void assign(size_type n, const T& t);  <font color="red">// CC and CA</font>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  lib.deque.capacity capacity:
    size_type size() const;
    size_type max_size() const;
    <b>void      resize(size_type sz);</b>  <font color="red">// Does not require CC</font>
    <b>void      resize(size_type sz, T c);</b>  <font color="red">// CC</font>
    bool      empty() const;

    //  element access:
    reference       operator[](size_type n);
    const_reference operator[](size_type n) const;
    reference       at(size_type n);
    const_reference at(size_type n) const;
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;

    //  lib.deque.modifiers modifiers:
    void push_front(const T& x);  <font color="red">// CC</font>
    <b>void push_front(T&& x);</b>
    void push_back(const T& x);  <font color="red">// CC</font>
    <b>void push_back(T&& x);</b>

    iterator insert(iterator position, const T& x);  <font color="red">// CC and CA</font>
    <b>iterator insert(iterator position, T&& x);</b>
    void     insert(iterator position, size_type n, const T& x);  <font color="red">// CC and CA</font>
    template &lt;class InputIterator&gt;
      void insert (iterator position,
                   InputIterator first,
                   InputIterator last);  <font color="red">// CC and CA only if InputIterator returns lvalue</font>

    void pop_front();
    void pop_back();

    iterator erase(iterator position);
    iterator erase(iterator first, iterator last);
    <b>void     swap(deque&&);</b>
    void     clear();
};

<b>
template &lt;class T, class Allocator&gt;
    void swap(deque&lt;T,Allocator&gt;& x, deque&lt;T,Allocator&gt;&& y);
template &lt;class T, class Allocator&gt;
    void swap(deque&lt;T,Allocator&gt;&& x, deque&lt;T,Allocator&gt;& y);
</b>
</pre></blockquote>

<h3>23.2.2 - Class template list</h3>

<blockquote><pre>
template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
class list {
  public:
    //  types:
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef T                                     value_type;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    //  lib.list.cons construct/copy/destroy:
    explicit list(const Allocator& = Allocator());
    <b>explicit list(size_type n);</b>  <font color="red">// Does not require CC</font>
    list(size_type n, const T& value,
         const Allocator& = Allocator());  <font color="red">// CC</font>
    template &lt;class InputIterator&gt;
      list(InputIterator first, InputIterator last,
           const Allocator& = Allocator());  <font color="red">// CC only if InputIterator returns lvalue</font>
    list(const list& x);  <font color="red">// CC</font>
    <b>list(list&& x);</b>
   ~list();
    list& operator=(const list& x);  <font color="red">// CC and CA</font>
    <b>list& operator=(list&& x);</b>
    template &lt;class InputIterator&gt;
      void assign(InputIterator first,
                  InputIterator last);  <font color="red">// CC and CA only if InputIterator returns lvalue</font>

    void assign(size_type n, const T& t);  <font color="red">// CC and CA</font>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  lib.list.capacity capacity:
    bool      empty() const;
    size_type size() const;
    size_type max_size() const;
    <b>void      resize(size_type sz);</b>  <font color="red">// Does not require CC</font>
    <b>void      resize(size_type sz, T c);</b>  <font color="red">// CC</font>

    //  element access:
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;

    //  lib.list.modifiers modifiers:
    void push_front(const T& x);  <font color="red">// CC</font>
    <b>void push_front(T&& x);</b>
    void pop_front();
    void push_back(const T& x);  <font color="red">// CC</font>
    <b>void push_back(T&& x);</b>
    void pop_back();

    iterator insert(iterator position, const T& x);  <font color="red">// CC</font>
    <b>iterator insert(iterator position, T&& x);</b>
    void     insert(iterator position, size_type n, const T& x);  <font color="red">// CC</font>
    template &lt;class InputIterator&gt;
      void insert(iterator position, InputIterator first,
                  InputIterator last);  <font color="red">// CC only if InputIterator returns lvalue</font>

    iterator erase(iterator position);
    iterator erase(iterator position, iterator last);
    <b>void     swap(list&&);</b>
    void     clear();

    //  lib.list.ops list operations:
    <b>void splice(iterator position, list&& x);</b>
    <b>void splice(iterator position, list&& x, iterator i);</b>
    <b>void splice(iterator position, list&& x, iterator first, iterator last);</b>

    void remove(const T& value);
    template &lt;class Predicate&gt; void remove_if(Predicate  pred );

    void unique();
    template &lt;class BinaryPredicate&gt;
      void unique(BinaryPredicate binary_pred);

    <b>void merge(list&& x);</b>
    <b>template &lt;class Compare&gt; void merge(list&& x , Compare comp);</b>

    void sort();
    template &lt;class Compare&gt; void sort(Compare comp);

    void reverse();
};

<b>
template &lt;class T, class Allocator&gt;
    void swap(list&lt;T,Allocator&gt;& x, list&lt;T,Allocator&gt;&& y);
template &lt;class T, class Allocator&gt;
    void swap(list&lt;T,Allocator&gt;&& x, list&lt;T,Allocator&gt;& y);
</b>
</pre></blockquote>

<h3>23.2.3.1 - Class template queue</h3>

<blockquote><pre>
template &lt;class T, class Container = deque&lt;T&gt; &gt;
class queue {
  public:
    typedef typename Container::value_type            value_type;
    typedef typename Container::size_type             size_type;
    typedef          Container                        container_type;
  protected:
    Container c;

  public:
    <b>explicit queue(const Container&);</b>    <font color="red">// CC</font>
    <b>explicit queue(Container&& = Container());</b>

    queue(const queue&);  <font color="red">// CC</font>
    <b>queue(queue&&);</b>
    queue& operator=(const queue&);    <font color="red">// CC and CA</font>
    <b>queue& operator=(queue&&);</b>

    bool      empty() const;
    size_type size()  const;
    value_type&       front();
    const value_type& front() const;
    value_type&       back();
    const value_type& back() const;
    void push(const value_type& x);  <font color="red">// CC</font>
    <b>void push(value_type&& x);</b>
    void pop();

    <b>void swap(queue&&);</b>
};

<b>
template &lt;class T, class Container&gt;
    void swap(queue&lt;T,Container&gt;& x, queue&lt;T,Container&gt;&& y);
template &lt;class T, class Container&gt;
    void swap(queue&lt;T,Container&gt;&& x, queue&lt;T,Container&gt;& y);
template &lt;class T, class Container&gt;
    void swap(queue&lt;T,Container&gt;& x, queue&lt;T,Container&gt;& y);
</b>
</pre></blockquote>

<h3>23.2.3.2 - Class template priority_queue</h3>

<blockquote><pre>
template &lt;class T, class Container = vector&lt;T&gt;,
            class Compare = less&lt;typename Container::value_type&gt; &gt;
  class priority_queue {
  public:
    typedef typename Container::value_type            value_type;
    typedef typename Container::size_type             size_type;
    typedef          Container                        container_type;
  protected:
    Container c;
    Compare comp;

  public:
    <b>priority_queue(const Compare& x,
                            const Container&);</b>  <font color="red">// CC</font>
    <b>explicit priority_queue(const Compare& x = Compare(),
                            Container&& = Container());</b>
    <b>template &lt;class InputIterator&gt;
      priority_queue(InputIterator first, InputIterator last,
                     const Compare& x,
                     const Container&);</b>  <font color="red">// CC</font>
    <b>template &lt;class InputIterator&gt;
      priority_queue(InputIterator first, InputIterator last,
                     const Compare& x = Compare(),
                     Container&& = Container());</b> <font color="red">// CC only if InputIterator returns lvalue</font>

    priority_queue(const priority_queue&);  <font color="red">// CC</font>
    <b>priority_queue(priority_queue&&);</b>
    priority_queue& operator=(const priority_queue&);  <font color="red">// CC and CA</font>
    <b>priority_queue& operator=(priority_queue&&);</b>

    bool      empty() const;
    size_type size()  const;
    const value_type& top() const;
    void push(const value_type& x);  <font color="red">// CC</font>
    <b>void push(value_type&& x);</b>
    void pop();
    <b>void swap(priority_queue&&);</b>
};

<b>
template &lt;class T, class Container, class Compare&gt;
    void swap(priority_queue&lt;T,Container,Compare&gt;& x,
              priority_queue&lt;T,Container,Compare&gt;&& y);
template &lt;class T, class Container, class Compare&gt;
    void swap(priority_queue&lt;T,Container,Compare&gt;&& x,
              priority_queue&lt;T,Container,Compare&gt;& y);
template &lt;class T, class Container, class Compare&gt;
    void swap(priority_queue&lt;T,Container,Compare&gt;& x,
              priority_queue&lt;T,Container,Compare&gt;& y);
</b>
</pre></blockquote>

<h3>23.2.3.3 - Class template stack</h3>

<blockquote><pre>

template &lt;class T, class Container = deque&lt;T&gt; &gt;
  class stack {
  public:
    typedef typename Container::value_type            value_type;
    typedef typename Container::size_type             size_type;
    typedef          Container                        container_type;
  protected:
    Container c;

  public:
    <b>explicit stack(const Container&);</b>  <font color="red">// CC</font>
    <b>explicit stack(Container&& = Container());</b>
    stack(const stack&);  <font color="red">// CC</font>
    <b>stack(stack&&);</b>
    stack& operator=(const stack&);  <font color="red">// CC</font>
    <b>stack& operator=(stack&&);</b>

    bool      empty() const;
    size_type size()  const;
    value_type&       top();
    const value_type& top() const;
    void push(const value_type& x);  <font color="red">// CC</font>
    <b>void push(value_type&& x);</b>
    void pop();

    <b>void swap(stack&&);</b>
};

<b>
template &lt;class T, class Container&gt;
    void swap(stack&lt;T,Container&gt;& x, stack&lt;T,Container&gt;&& y);
template &lt;class T, class Container&gt;
    void swap(stack&lt;T,Container&gt;&& x, stack&lt;T,Container&gt;& y);
template &lt;class T, class Container&gt;
    void swap(stack&lt;T,Container&gt;& x, stack&lt;T,Container&gt;& y);
</b>
</pre></blockquote>

<h3>23.2.4 - Class template vector</h3>

<blockquote><pre>
template &lt;class T, class Allocator = allocator&lt;T&gt; &gt;
class vector {
  public:
    //  types:
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef T                                     value_type;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    //  lib.vector.cons construct/copy/destroy:
    explicit vector(const Allocator& = Allocator());
    <b>explicit vector(size_type n);</b>  <font color="red">// Does not require CC</font>
    vector(size_type n, const T& value,
           const Allocator& = Allocator());  <font color="red">// CC</font>
    template &lt;class InputIterator&gt;
      vector(InputIterator first, InputIterator last,
             const Allocator& = Allocator());  <font color="red">// CC only if InputIterator returns lvalue</font>
    vector(const vector& x);  <font color="red">// CC</font>
    <b>vector(vector&& x);</b>
   ~vector();
    vector& operator=(const vector& x);  <font color="red">// CC and CA</font>
    <b>vector& operator=(vector&& x);</b>
    template &lt;class InputIterator&gt;
      void assign(InputIterator first,
                  InputIterator last);  <font color="red">// CC and CA only if InputIterator returns lvalue</font>
    void assign(size_type n, const T& u);  <font color="red">// CC and CA</font>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  lib.vector.capacity capacity:
    size_type size() const;
    size_type max_size() const;
    <b>void      resize(size_type sz);</b>  <font color="red">// Does not require CC</font>
    <b>void      resize(size_type sz, T c);</b>  <font color="red">// CC</font>
    size_type capacity() const;
    bool      empty() const;
    void      reserve(size_type n);

    //  element access:
    reference       operator[](size_type n);
    const_reference operator[](size_type n) const;
    const_reference at(size_type n) const;
    reference       at(size_type n);
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;

    //  lib.vector.modifiers modifiers:
    void push_back(const T& x);  <font color="red">// CC</font>
    <b>void push_back(T&& x);</b>
    void pop_back();
    iterator insert(iterator position, const T& x);  <font color="red">// CC and CA</font>
    <b>iterator insert(iterator position, T&& x);</b>
    void     insert(iterator position, size_type n, const T& x);  <font color="red">// CC and CA</font>
    template &lt;class InputIterator&gt;
        void insert(iterator position,
                    InputIterator first,
                    InputIterator last); <font color="red">// CC and CA only if InputIterator returns lvalue</font>
    iterator erase(iterator position);
    iterator erase(iterator first, iterator last);
    <b>void     swap(vector&&);</b>
    void     clear();
};

<b>
template &lt;class T, class Allocator&gt;
    void swap(vector&lt;T,Allocator&gt;& x, vector&lt;T,Allocator&gt;&& y);
template &lt;class T, class Allocator&gt;
    void swap(vector&lt;T,Allocator&gt;&& x, vector&lt;T,Allocator&gt;& y);
</b>
</pre></blockquote>

<h3>23.2.5 - Class vector&lt;bool&gt;</h3>

<blockquote><pre>
template &lt;class Allocator&gt; class vector&lt;bool, Allocator&gt; {
  public:
    //  types:
    typedef bool                                  const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef bool                                  value_type;
    typedef Allocator                             allocator_type;
    typedef implementation defined                pointer;
    typedef implementation defined                const_pointer
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    //  bit reference:
    class reference {
     friend class vector;
     reference();
    public:
     ~reference();
      operator bool() const;
      reference& operator=(const bool x);
      reference& operator=(const reference& x);
      void flip();              //  flips the bit
    };

    //  construct/copy/destroy:
    explicit vector(const Allocator& = Allocator());
    vector(size_type n, const bool& value, const Allocator& = Allocator());
    template &lt;class InputIterator&gt;
      vector(InputIterator first, InputIterator last,
             const Allocator& = Allocator());
    vector(const vector& x);
    <b>vector(vector&& x);</b>
   ~vector();
    vector& operator=(const vector& x);
    <b>vector& operator=(vector&& x);</b>
    template &lt;class InputIterator&gt;
      void assign(InputIterator first, InputIterator last);
    void assign(size_type n, const T& t);
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  capacity:
    size_type size() const;
    size_type max_size() const;
    void      resize(size_type sz, bool c = false);
    size_type capacity() const;
    bool      empty() const;
    void      reserve(size_type n);

    //  element access:
    reference       operator[](size_type n);
    const_reference operator[](size_type n) const;
    const_reference at(size_type n) const;
    reference       at(size_type n);
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;

    //  modifiers:
    void push_back(const bool& x);
    void pop_back();
    iterator insert(iterator position, const bool& x);
    void     insert (iterator position, size_type n, const bool& x);
    template &lt;class InputIterator&gt;
        void insert(iterator position,
                    InputIterator first, InputIterator last);

    iterator erase(iterator position);
    iterator erase(iterator first, iterator last);
    <b>void swap(vector&&);</b>
    static void swap(reference x, reference y);
    void flip();                //  flips all bits
    void clear();
};
</pre></blockquote>

<h3>23.3.1 - Class template map</h3>

<p>
Note below that for <tt>map</tt> and <tt>multimap</tt> that there are two new
insert overloads, both taking a <tt>pair</tt> with a non-const
<tt>key_type</tt>.  One can not move from a <tt>const key_type</tt>, and
therefore to be able to move a <tt>key_type</tt> into the <tt>(multi)map</tt>, a
<tt>pair&lt;key_type, mapped_type&gt;</tt> must be used.  There are overloads
for both a const lvalue <tt>pair&lt;key_type, mapped_type&gt;</tt>, and a
non-const rvalue <tt>pair&lt;key_type, mapped_type&gt;</tt> so that lvalue
<tt>pair&lt;key_type, mapped_type&gt;</tt>'s will not be moved from.
</p>

<blockquote><pre>
template &lt;class Key, class T, class Compare = less&lt;Key&gt;,
          class Allocator = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
class map {
  public:
    //  types:
    typedef Key                                   key_type;
    typedef T                                     mapped_type;
    typedef pair&lt;const Key, T&gt;                    value_type;
    typedef Compare                               key_compare;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    class value_compare
      : public binary_function&lt;value_type,value_type,bool&gt; {
    friend class map;
    protected:
      Compare comp;
      value_compare(Compare c) : comp(c) {}
    public:
      bool operator()(const value_type& x, const value_type& y) const {
        return comp(x.first, y.first);
      }
    };

    //  lib.map.cons construct/copy/destroy:
    explicit map(const Compare& comp = Compare(), const Allocator& a = Allocator());
    template &lt;class InputIterator&gt;
      map(InputIterator first, InputIterator last,
          const Compare& comp = Compare(),
          const Allocator& a = Allocator());  <font color="red">// CC only if InputIterator returns lvalue</font>
    map(const map& x);  <font color="red">// CC</font>
    <b>map(map&& x);</b>
   ~map();
    map& operator=(const map& x);  <font color="red">// CC</font>
    <b>map& operator=(map&& x);</b>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  capacity:
    bool      empty() const;
    size_type size() const;
    size_type max_size() const;

    //  lib.map.access element access:
    T& operator[](const key_type& x);  <font color="red">// CC for key_type only</font>
    <b>T& operator[](key_type&& x);</b>

    //  modifiers:
    pair&lt;iterator, bool&gt; insert(const value_type& x);  <font color="red">// CC</font>
    <b>pair&lt;iterator, bool&gt; insert(const pair&lt;key_type,mapped_type&gt;& x);</b>  <font color="red">// CC</font>
    <b>pair&lt;iterator, bool&gt; insert(pair&lt;key_type,mapped_type&gt;&& x);</b>
    iterator insert(iterator position, const value_type& x);  <font color="red">// CC</font>
    <b>iterator insert(iterator position, const pair&lt;key_type,mapped_type&gt;& x);</b>  <font color="red">// CC</font>
    <b>iterator insert(iterator position, pair&lt;key_type,mapped_type&gt;&& x);</b>
    template &lt;class InputIterator&gt;
      void insert(InputIterator first,
                  InputIterator last);  <font color="red">// CC only if InputIterator returns lvalue</font>

    void      erase(iterator position);
    size_type erase(const key_type& x);
    void      erase(iterator first, iterator last);
    <b>void swap(map&&);</b>
    void clear();

    //  observers:
    key_compare   key_comp() const;
    value_compare value_comp() const;

    //  lib.map.ops map operations:
    iterator       find(const key_type& x);
    const_iterator find(const key_type& x) const;
    size_type      count(const key_type& x) const;

    iterator       lower_bound(const key_type& x);
    const_iterator lower_bound(const key_type& x) const;
    iterator       upper_bound(const key_type& x);
    const_iterator upper_bound(const key_type& x) const;

    pair&lt;iterator,iterator&gt;
        equal_range(const key_type& x);
    pair&lt;const_iterator,const_iterator&gt;
        equal_range(const key_type& x) const;
};

<b>
template &lt;class Key, class T, class Compare, class Allocator&gt;
    void swap(map&lt;Key,T,Compare,Allocator&gt;& x,
              map&lt;Key,T,Compare,Allocator&gt;&& y);
template &lt;class Key, class T, class Compare, class Allocator&gt;
    void swap(map&lt;Key,T,Compare,Allocator&gt;&& x,
              map&lt;Key,T,Compare,Allocator&gt;& y);
</b>
</pre></blockquote>

<h3>23.3.2 - Class template multimap</h3>

<blockquote><pre>
template &lt;class Key, class T, class Compare = less&lt;Key&gt;,
            class Allocator = allocator&lt;pair&lt;const Key, T&gt; &gt; &gt;
class multimap {
  public:
    //  types:
    typedef Key                                   key_type;
    typedef T                                     mapped_type;
    typedef pair&lt;const Key,T&gt;                     value_type;
    typedef Compare                               key_compare;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    class value_compare
      : public binary_function&lt;value_type,value_type,bool&gt; {
    friend class multimap;
    protected:
      Compare comp;
      value_compare(Compare c) : comp(c) {}
    public:
      bool operator()(const value_type& x, const value_type& y) const {
        return comp(x.first, y.first);
      }
    };

    //  construct/copy/destroy:
    explicit multimap(const Compare& comp = Compare(),
                      const Allocator& = Allocator());
    template &lt;class InputIterator&gt;
      multimap(InputIterator first, InputIterator last,
               const Compare& comp = Compare(),
               const Allocator& = Allocator()); <font color="red">// CC only if InputIterator returns lvalue</font>
    multimap(const multimap& x);  <font color="red">// CC</font>
    <b>multimap(multimap&& x);</b>
   ~multimap();
    multimap& operator=(const multimap& x);  <font color="red">// CC</font>
    <b>multimap& operator=(multimap&& x);</b>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  capacity:
    bool           empty() const;
    size_type      size() const;
    size_type      max_size() const;

    //  modifiers:
    iterator insert(const value_type& x);  <font color="red">// CC</font>
    <b>iterator insert(const pair&lt;key_type,mapped_type&gt;& x);</b>  <font color="red">// CC</font>
    <b>iterator insert(pair&lt;key_type,mapped_type&gt;&& x);</b>
    iterator insert(iterator position, const value_type& x);  <font color="red">// CC</font>
    <b>iterator insert(iterator position, const pair&lt;key_type,mapped_type&gt;& x);</b>  <font color="red">// CC</font>
    <b>iterator insert(iterator position, pair&lt;key_type,mapped_type&gt;&& x);</b>
    template &lt;class InputIterator&gt;
      void insert(InputIterator first,
                  InputIterator last);  <font color="red">// CC only if InputIterator returns lvalue</font>

    void      erase(iterator position);
    size_type erase(const key_type& x);
    void      erase(iterator first, iterator last);
    <b>void swap(multimap&&);</b>
    void clear();

    //  observers:
    key_compare    key_comp() const;
    value_compare  value_comp() const;

    //  map operations:
    iterator       find(const key_type& x);
    const_iterator find(const key_type& x) const;
    size_type      count(const key_type& x) const;

    iterator       lower_bound(const key_type& x);
    const_iterator lower_bound(const key_type& x) const;
    iterator       upper_bound(const key_type& x);
    const_iterator upper_bound(const key_type& x) const;

    pair&lt;iterator,iterator&gt;
      equal_range(const key_type& x);
    pair&lt;const_iterator,const_iterator&gt;
      equal_range(const key_type& x) const;
  };

<b>
template &lt;class Key, class T, class Compare, class Allocator&gt;
    void swap(multimap&lt;Key,T,Compare,Allocator&gt;& x,
              multimap&lt;Key,T,Compare,Allocator&gt;&& y);
template &lt;class Key, class T, class Compare, class Allocator&gt;
    void swap(multimap&lt;Key,T,Compare,Allocator&gt;&& x,
              multimap&lt;Key,T,Compare,Allocator&gt;& y);
</b>
</pre></blockquote>

<h3>23.3.3 - Class template set</h3>

<blockquote><pre>
template &lt;class Key, class Compare = less&lt;Key&gt;,
          class Allocator = allocator&lt;Key&gt; &gt;
  class set {
  public:
    //  types:
    typedef Key                                   key_type;
    typedef Key                                   value_type;
    typedef Compare                               key_compare;
    typedef Compare                               value_compare;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    //  lib.set.cons construct/copy/destroy:
    explicit set(const Compare& comp = Compare(),
                 const Allocator& = Allocator());
    template &lt;class InputIterator&gt;
      set(InputIterator first, InputIterator last,
          const Compare& comp = Compare(),
          const Allocator& = Allocator());  <font color="red">// CC only if InputIterator returns lvalue</font>
    set(const set& x);  <font color="red">// CC</font>
    <b>set(set&& x);</b>
   ~set();
    set& operator= (const set& x);  <font color="red">// CC</font>
    <b>set& operator= (set&& x);</b>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  capacity:
    bool          empty() const;
    size_type     size() const;
    size_type     max_size() const;

    //  modifiers:
    pair&lt;iterator,bool&gt; insert(const value_type& x);  <font color="red">// CC</font>
    <b>pair&lt;iterator,bool&gt; insert(value_type&& x);</b>
    iterator            insert(iterator position, const value_type& x);  <font color="red">// CC</font>
    <b>iterator            insert(iterator position, value_type&& x);</b>
    template &lt;class InputIterator&gt;
        void insert(InputIterator first,
                    InputIterator last);  <font color="red">// CC only if InputIterator returns lvalue</font>

    void      erase(iterator position);
    size_type erase(const key_type& x);
    void      erase(iterator first, iterator last);
    <b>void swap(set&&);</b>
    void clear();

    //  observers:
    key_compare   key_comp() const;
    value_compare value_comp() const;

    //  set operations:
    iterator  find(const key_type& x) const;
    size_type count(const key_type& x) const;

    iterator  lower_bound(const key_type& x) const;
    iterator  upper_bound(const key_type& x) const;
    pair&lt;iterator,iterator&gt; equal_range(const key_type& x) const;
};

<b>
template &lt;class Key, class Compare, class Allocator&gt;
    void swap(set&lt;Key,Compare,Allocator&gt;& x,
              set&lt;Key,Compare,Allocator&gt;&& y);
template &lt;class Key, class Compare, class Allocator&gt;
    void swap(set&lt;Key,Compare,Allocator&gt;&& x,
              set&lt;Key,Compare,Allocator&gt;& y);
</b>
</pre></blockquote>

<h3>23.3.4 - Class template multiset</h3>

<blockquote><pre>
template &lt;class Key, class Compare = less&lt;Key&gt;,
          class Allocator = allocator&lt;Key&gt; &gt;
  class multiset {
  public:
    //  types:
    typedef Key                                   key_type;
    typedef Key                                   value_type;
    typedef Compare                               key_compare;
    typedef Compare                               value_compare;
    typedef Allocator                             allocator_type;
    typedef typename Allocator::reference         reference;
    typedef typename Allocator::const_reference   const_reference;
    typedef implementation defined                iterator;
    typedef implementation defined                const_iterator;
    typedef implementation defined                size_type;
    typedef implementation defined                difference_type;
    typedef typename Allocator::pointer           pointer;
    typedef typename Allocator::const_pointer     const_pointer;
    typedef std::reverse_iterator&lt;iterator&gt;       reverse_iterator;
    typedef std::reverse_iterator&lt;const_iterator&gt; const_reverse_iterator;

    //  construct/copy/destroy:
    explicit multiset(const Compare& comp = Compare(),
                      const Allocator& = Allocator());
    template &lt;class InputIterator&gt;
      multiset(InputIterator first, InputIterator last,
               const Compare& comp = Compare(),
               const Allocator& = Allocator()); <font color="red">// CC only if InputIterator returns lvalue</font>
    multiset(const multiset& x);  <font color="red">// CC</font>
    <b>multiset(multiset&& x);</b>
   ~multiset();
    multiset& operator=(const multiset& x);  <font color="red">// CC</font>
    <b>multiset& operator=(multiset&& x);</b>
    allocator_type get_allocator() const;

    //  iterators:
    iterator               begin();
    const_iterator         begin() const;
    iterator               end();
    const_iterator         end() const;
    reverse_iterator       rbegin();
    const_reverse_iterator rbegin() const;
    reverse_iterator       rend();
    const_reverse_iterator rend() const;

    //  capacity:
    bool          empty() const;
    size_type     size() const;
    size_type     max_size() const;

    //  modifiers:
    iterator insert(const value_type& x);  <font color="red">// CC</font>
    <b>iterator insert(value_type&& x);</b>
    iterator insert(iterator position, const value_type& x);  <font color="red">// CC</font>
    <b>iterator insert(iterator position, value_type&& x);</b>
    template &lt;class InputIterator&gt;
      void insert(InputIterator first,
                  InputIterator last);  <font color="red">// CC only if InputIterator returns lvalue</font>

    void      erase(iterator position);
    size_type erase(const key_type& x);
    void      erase(iterator first, iterator last);
    <b>void swap(multiset&&);</b>
    void clear();

    //  observers:
    key_compare   key_comp() const;
    value_compare value_comp() const;

    //  set operations:
    iterator  find(const key_type& x) const;
    size_type count(const key_type& x) const;

    iterator  lower_bound(const key_type& x) const;
    iterator  upper_bound(const key_type& x) const;
    pair&lt;iterator,iterator&gt; equal_range(const key_type& x) const;
};

<b>
template &lt;class Key, class Compare, class Allocator&gt;
    void swap(multiset&lt;Key,Compare,Allocator&gt;& x,
              multiset&lt;Key,Compare,Allocator&gt;&& y);
template &lt;class Key, class Compare, class Allocator&gt;
    void swap(multiset&lt;Key,Compare,Allocator&gt;&& x,
              multiset&lt;Key,Compare,Allocator&gt;& y);
</b>
</pre></blockquote>

<h2>24 - Iterators library</h2>

<p>
A new iterator adaptor is needed which returns an rvalue reference instead of an
lvalue reference on dereference.  Ideally this iterator adaptor will be part of
a more general iterator adaptor package.  However for the purposes of this
paper, the iterator adaptor can be considered a standalone adaptor like the
existing standard iterator adaptors.  The proposed adaptor also does not fit
neatly into an existing iterator category.  It is a <i>read-once</i> iterator,
but can have up to random access traversal characteristics.
</p>

<blockquote><pre>
template &lt;class Iterator&gt;
class move_iterator
{
public:
    typedef Iterator                                              iterator_type;
    typedef typename iterator_traits&lt;Iterator&gt;::difference_type   difference_type;
    typedef typename iterator_traits&lt;Iterator&gt;::pointer           pointer;
    typedef typename iterator_traits&lt;Iterator&gt;::value_type        value_type;
    typedef typename iterator_traits&lt;Iterator&gt;::iterator_category iterator_category;
    typedef value_type&&                                          reference;

    move_iterator();
    explicit move_iterator(iterator_type i);
    template &lt;class U&gt; move_iterator(const move_iterator&lt;U&gt;& u);

    iterator_type base() const;
    reference operator*() const;
    pointer   operator-&gt;() const;

    move_iterator& operator++();
    move_iterator  operator++(int);
    move_iterator& operator--();
    move_iterator  operator--(int);

    move_iterator  operator+ (difference_type n) const;
    move_iterator& operator+=(difference_type n);
    move_iterator  operator- (difference_type n) const;
    move_iterator& operator-=(difference_type n);
    reference operator[](difference_type n) const;
};

template &lt;class Iterator&gt;
bool
operator==(const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
bool
operator!=(const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
bool
operator&lt; (const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
bool
operator&lt;=(const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
bool
operator&gt; (const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
bool
operator&gt;=(const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
typename move_iterator&lt;Iterator&gt;::difference_type
operator-(const move_iterator&lt;Iterator&gt;& x, const move_iterator&lt;Iterator&gt;& y);

template &lt;class Iterator&gt;
move_iterator&lt;Iterator&gt;
operator+(typename move_iterator&lt;Iterator&gt;::difference_type n,
          const move_iterator&lt;Iterator&gt;& x);

template &lt;class Iterator&gt;
move_iterator&lt;Iterator&gt;
make_move_iterator(const Iterator& i);
</pre></blockquote>

<p>
Given the above tool, "copying" algorithms can be turned into "moving"
algorithms by adapting the iterators appropriately.  For example:
</p>

<blockquote><pre>
vector&lt;unique_ptr&lt;int&gt; &gt; v1, v2;
...
remove_copy(make_move_iterator(v1.begin()), make_move_iterator(v1.end()),
            back_inserter(v2), unique_ptr&lt;int&gt;());
</pre></blockquote>

<p>
This call to <tt>remove_copy</tt> <i>moves</i> all non-null
<tt>unique_ptr</tt>'s from <tt>v1</tt> to <tt>v2</tt>.
</p>

<p>
The following modifications to the existing iterator adaptors allows them to
work with movable but non-copyable types that are presented to the assignment
operator as an rvalue (as in the <tt>remove_copy</tt> example above).
</p>

<h3>24.4.2.1 - Class template back_insert_iterator</h3>

<blockquote><pre>
template &lt;class Container&gt;
class back_insert_iterator :
    public iterator&lt;output_iterator_tag,void,void,void,void&gt; {
protected:
    Container* container;

public:
    typedef Container container_type;
    explicit back_insert_iterator(Container& x);
    back_insert_iterator&lt;Container&gt;&
      operator=(typename Container::const_reference value);
<b>    back_insert_iterator&lt;Container&gt;&
      operator=(typename Container::value_type&& value);</b>

    back_insert_iterator&lt;Container&gt;& operator*();
    back_insert_iterator&lt;Container&gt;& operator++();
    back_insert_iterator&lt;Container&gt;  operator++(int);
};
</pre></blockquote>

<h3>24.4.2.3 - Class template front_insert_iterator</h3>

<blockquote><pre>
template &lt;class Container&gt;
class front_insert_iterator :
    public iterator&lt;output_iterator_tag,void,void,void,void&gt; {
protected:
    Container* container;

public:
    typedef Container container_type;
    explicit front_insert_iterator(Container& x);
    front_insert_iterator&lt;Container&gt;&
      operator=(typename Container::const_reference value);
<b>    front_insert_iterator&lt;Container&gt;&
      operator=(typename Container::value_type&& value);</b>

    front_insert_iterator&lt;Container&gt;& operator*();
    front_insert_iterator&lt;Container&gt;& operator++();
    front_insert_iterator&lt;Container&gt;  operator++(int);
};
</pre></blockquote>

<h3>24.4.2.5 - Class template insert_iterator</h3>

<blockquote><pre>
template &lt;class Container&gt;
class insert_iterator :
    public iterator&lt;output_iterator_tag,void,void,void,void&gt; {
protected:
    Container* container;
    typename Container::iterator iter;

public:
    typedef Container container_type;
    insert_iterator(Container& x, typename Container::iterator i);
    insert_iterator&lt;Container&gt;&
      operator=(typename Container::const_reference value);
<b>    insert_iterator&lt;Container&gt;&
      operator=(typename Container::value_type&& value);</b>

    insert_iterator&lt;Container&gt;& operator*();
    insert_iterator&lt;Container&gt;& operator++();
    insert_iterator&lt;Container&gt;& operator++(int);
};
</pre></blockquote>

<h2>25 - Algorithms library</h2>

<p>
There are two new algorithms, one with a slightly altered signature, and several
with relaxed requirements (no longer requiring <tt>CopyConstructible</tt> or
<tt>CopyAssignable</tt>) so that ranges of movable but non-copyable elemens
(such as <tt>unique_ptr</tt>) can be operated on.
</p>

<blockquote><pre>
template &lt;class InputIterator, class OutputIterator&gt;
    OutputIterator move(InputIterator first, InputIterator last,
                        OutputIterator result);

template &lt;class BidirectionalIterator1, class BidirectionalIterator2&gt;
    BidirectionalIterator2
      move_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
                    BidirectionalIterator2 result);
</pre></blockquote>

<p>
<tt>move</tt> and <tt>move_backward</tt> are two new algorithms to augment
<tt>copy</tt> and <tt>copy_backward</tt>.  They require only that the value_type
be <tt>MoveAssignable</tt> (recall that <tt>CopyAssignable</tt> types are
<tt>MoveAssignable</tt>).  Strictly speaking the functionality could be obtained
with the combination of <tt>copy</tt> (or <tt>copy_backward</tt>) and
<tt>move_iterator</tt>, however the anticipated frequency of use of these
functions indicates that the syntactic convenience of these functions is
warranted.
</p>

<p>
The table below summarizes the following five requirements for each algorithm in
<tt>&lt;algorithm&gt;</tt>.  Other requirements on the algorithms are ignored in
this table.
</p>

<ul>
<li><tt>Swappable</tt> abbreviated as <tt>S</tt></li>
<li><tt>MoveConstructible</tt> abbreviated as <tt>MC</tt></li>
<li><tt>MoveAssignable</tt> abbreviated as <tt>MA</tt></li>
<li><tt>CopyConstructible</tt> abbreviated as <tt>CC</tt></li>
<li><tt>CopyAssignable</tt> abbreviated as <tt>CA</tt></li>
</ul>

<p>
The table below is a contract between clients and the implementation.  The
client must supply types that meet the minimum requirements.  The type may also
meet additional requirements.  The implementation may assume that the supplied
client type meets all of the requirements listed for an algorithm.  But the
implementation is not required to exercise all of the requirements.  However the
implementation is banned from using requirements not listed for the algorithm.
</p>

<p>
Those algorithms with the <tt>Swappable</tt> requirement may call <tt>swap</tt>
unqualified, allowing for argument dependent lookup to find a <tt>swap</tt> in
the client's namespace.  Those algorithms without the <tt>Swappable</tt>
requirement must not call <tt>swap</tt> unqualified.  Furthermore, those
algorithms without both <tt>MoveConstructible</tt> and <tt>MoveAssignable</tt>
must not call <tt>swap</tt> qualified as the standard <tt>swap</tt> has these
requirements.
</p>

<p>
Any algorithm may call any other algorithm qualified if the called algorithm's
requirements are a subset of the calling algorithm's requirements (including
<tt>std::swap</tt>).
</p>

<p>
No algorithm may call another algorithm unqualified unless such a call is part
of a concept requirement of the algorithm (<tt>Swappable</tt> being the only
example discussed).
</p>

<p>
Note that the requirements listed below allow many algorithms to operate on
ranges of movable but non-copyable types such as <tt>unique_ptr</tt>.
Furthermore, a few algorithms will operate on types supporting only the
<tt>Swappable</tt> requirement (even if they are neither movable nor copyable).
</p>

<p>
The non-mutating algorithms have no requirements along these lines, but are
listed below for completeness.
</p>

<p><center>
<table border="1">

<caption>Summary of algorithm requirements</caption>

<tr><th>algorithm</th> <th><tt>S</tt></th> <th><tt>MC</tt></th> <th><tt>MA</tt></th> <th><tt>CC</tt></th> <th><tt>CA</tt></th> <th>Remarks</th></tr>

<tr><td><tt>for_each</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>find</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>find_if</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>find_end</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>find_first_of</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>adjacent_find</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>count</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>count_if</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>mismatch</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>equal</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>search</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>search_n</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>copy</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td></tr>

<tr><td><tt>copy_backward</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td></tr>

<tr><td><tt>move</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>This is a new algorithm</td></tr>

<tr><td><tt>move_backward</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>This is a new algorithm</td></tr>

<tr><td><tt>swap</tt></td> <td>&nbsp;</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>swap_ranges</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>iter_swap</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>transform</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>X</td> <td>If the operation returns an rvalue, only <tt>MA</tt> is required</td></tr>

<tr><td><tt>replace</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td></tr>

<tr><td><tt>replace_if</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td></tr>

<tr><td><tt>replace_copy</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

</table>
</center></p>

<p><center>
<table border="1">

<caption>Summary of algorithm requirements (continued)</caption>

<tr><th>algorithm</th> <th><tt>S</tt></th> <th><tt>MC</tt></th> <th><tt>MA</tt></th> <th><tt>CC</tt></th> <th><tt>CA</tt></th> <th>Remarks</th></tr>

<tr><td><tt>replace_copy_if</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>fill</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td></tr>

<tr><td><tt>fill_n</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td></tr>

<tr><td><tt>generate</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>X</td> <td>If the generator returns an rvalue, only <tt>MA</tt> is required</td></tr>

<tr><td><tt>generate_n</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>X</td> <td>If the generator returns an rvalue, only <tt>MA</tt> is required</td></tr>

<tr><td><tt>remove</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>remove_if</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>remove_copy</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>remove_copy_if</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>unique</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>unique_copy</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>reverse</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>reverse_copy</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>rotate</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>rotate_copy</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>random_shuffle</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>partition</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>stable_partition</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>sort</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>stable_sort</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>partial_sort</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>partial_sort_copy</tt></td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td>Applies only to output range</td></tr>

<tr><td><tt>nth_element</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

</table>
</center></p>

<p><center>
<table border="1">

<caption>Summary of algorithm requirements (continued)</caption>

<tr><th>algorithm</th> <th><tt>S</tt></th> <th><tt>MC</tt></th> <th><tt>MA</tt></th> <th><tt>CC</tt></th> <th><tt>CA</tt></th> <th>Remarks</th></tr>

<tr><td><tt>lower_bound</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>upper_bound</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>equal_range</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>binary_search</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>merge</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>inplace_merge</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>includes</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>set_union</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>set_intersection</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>set_difference</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>set_symmetric_difference</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>X</td> <td><tt>CA</tt> applies only to the output range</td></tr>

<tr><td><tt>push_heap</tt></td> <td>&nbsp;</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>pop_heap</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>make_heap</tt></td> <td>&nbsp;</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>sort_heap</tt></td> <td>X</td> <td>X</td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>min</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>max</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>min_element</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>max_element</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>lexicographical_compare</tt></td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>next_permutation</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

<tr><td><tt>prev_permutation</tt></td> <td>X</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td></tr>

</table>
</center></p>

<p>[<i>Example:</i></p>
<blockquote>
<tt>swap_ranges</tt> has only the <tt>Swappable</tt> requirement.  It must call
<tt>swap</tt> unqualified if it is to move any elements around.  No other
element moving call is allowed.
</blockquote>
<p><i>-- end example</i>]</p>

<p>[<i>Example:</i></p>
<blockquote>
<tt>rotate</tt> requires <tt>Swappable</tt>, <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt>.  It is allowed to call <tt>swap</tt> unqualified,
<tt>swap</tt> qualified, or to not call <tt>swap</tt> at all, instead calling
the element's move assignment and/or move constructor.  <tt>rotate</tt> may not
call the element's copy constructor or copy assignment.
</blockquote>
<p><i>-- end example</i>]</p>

<p>[<i>Example:</i></p>
<blockquote>
<tt>push_heap</tt> requires <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt> (but not <tt>Swappable</tt>).  It is allowed to call
<tt>swap</tt> qualified, and allowed to move elements with a move constructor or
move assignment.  <tt>push_heap</tt> must not call <tt>swap</tt> unqualified,
nor the element's copy constructor or copy assignment.
</blockquote>
<p><i>-- end example</i>]</p>

<p>
The signature of <tt>random_shuffle</tt> is changed to allow an rvalue random
number generator:
</p>

<blockquote><pre>
template &lt;class RandomAccessIterator&gt;
  void random_shuffle(RandomAccessIterator first,
                      RandomAccessIterator last,
                      RandomNumberGenerator<del>&</del><ins>&&</ins> rand);
</pre></blockquote>

<a name="insertion_sort"></a><h4>Transition note for library vendors:</h4>

<p>
For exposition purposes, below is shown how an example algorithm might be
modified to reduce its requirements from <tt>CopyConstructible</tt> and
<tt>CopyAssignable</tt> to <tt>MoveConstructible</tt> and
<tt>MoveAssignable</tt>.  The algorithm today might look like:
</p>

<blockquote><pre>
template &lt;class BidirectionalIterator&gt;
void
insertion_sort(BidirectionalIterator first, BidirectionalIterator last)
{
    typedef typename iterator_traits&lt;BidirectionalIterator&gt;::value_type value_type;
    if (first != last)
    {
        BidirectionalIterator i = first;
        for (++i; i != last; ++i)
        {
            BidirectionalIterator j = i;
            value_type tmp(*j);
            for (BidirectionalIterator k = i; k != first && tmp &lt; *--k; --j)
                *j = *k;
            *j = tmp;
        }
    }
}
</pre></blockquote>

<p>
Careful analysis of the above function reveals that the value of each
<tt>value_type</tt> copied from is never used again.  Therefore the only thing
required to greatly accelerate the speed of this algorithm when used with heavy
weight but movable <tt>value_type</tt>'s is to replace the copy construction and
copy assignment with their <tt>move</tt> counterparts:
</p>

<blockquote><pre>
template &lt;class BidirectionalIterator&gt;
void
insertion_sort(BidirectionalIterator first, BidirectionalIterator last)
{
    typedef typename iterator_traits&lt;BidirectionalIterator&gt;::value_type value_type;
    if (first != last)
    {
        BidirectionalIterator i = first;
        for (++i; i != last; ++i)
        {
            BidirectionalIterator j = i;
            value_type tmp(<b>std::move(</b>*j<b>)</b>);
            for (BidirectionalIterator k = i; k != first && tmp &lt; *--k; --j)
                *j = <b>std::move(</b>*k<b>)</b>;
            *j = <b>std::move(</b>tmp<b>)</b>;
        }
    }
}
</pre></blockquote>

<p>
When working with older compilers not yet implementing the rvalue reference, if
the library supplies an <a href="#old_move"><i>interim</i> <tt>move</tt>
function</a>, then the above insertion_sort will continue to work on these older
compilers as it did before modification (requiring copy semantics instead of
move semantics).
</p>

<h2>26 - Numerics library</h2>

<h3>26.3.2 - Class template valarray</h3>

<p>
<b>Summary:</b>  Give <tt>valarray</tt> a move constructor and move assignment
operator.
</p>

<p>Add:</p>

<blockquote><pre>
valarray(valarray&&);
valarray& operator=(valarray&&);
</pre></blockquote>

<h2>27 - Input/output library</h2>

<p>
<b>Summary:</b>  Make streams move constructible, move assignable and swappable.
 Enable clients to work with rvalue streams for <tt>operator &lt;&lt</tt> and
<tt>operator &gt;&gt</tt>.
</p>

<h3>27.4.4 - Class template basic_ios</h3>

<p>Add to <tt>basic_ios</tt> protected members:</p>

<blockquote><pre>
void move(basic_ios&& rhs);
void swap(basic_ios&& rhs);
void set_rdbuf(basic_streambuf&lt;charT, traits&gt;* sb);
</pre></blockquote>

<p>
Derived clients can call <tt>move</tt> as an aid in move construction, similar
to <tt>basic_ios::init</tt>.  Similarly for <tt>swap</tt>.  Neither
<tt>move</tt> nor <tt>swap</tt> are allowed to change the result which
<tt>rdbuf()</tt> returns.  That is, this member remains unchanged through these
calls.  Derived clients must set this data via <tt>set_rdbuf</tt>.  Like
<tt>rdbuf</tt>, the new, protected <tt>set_rdbuf</tt> sets the
<tt>streambuf</tt> associated with the stream, but it does not call
<tt>clear()</tt> as the public <tt>rdbuf()</tt> does.
</p>

<h3>27.5.2 - Class template basic_streambuf&lt;charT,traits&gt;</h3>

<p>Add to <tt>basic_streambuf</tt> protected members:</p>

<blockquote><pre>
basic_streambuf(const basic_streambuf& rhs);
basic_streambuf& operator=(const basic_streambuf& rhs);
void swap(basic_streambuf&& rhs);
</pre></blockquote>

<p>
This affects <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#421">LWG issue
421</a> which concerns whether or not <tt>basic_streambuf</tt> has copy
semantics.  It turns out that when writing move constructors and move assignment
for clients derived from <tt>basic_streambuf</tt> that it is sometimes very
handy to ask the base to move construct, move assign, or swap.  These operations
are possible to do in the derived client by calling <tt>pubimbue</tt>,
<tt>setg</tt>, <tt>pbump</tt>, <tt>eback</tt>, etc.  However, using this
interface is extremely clumsy and inefficient for this purpose.
</p>

<p>
An alternative is to declare that <tt>basic_streambuf</tt> has private copy
semantics, but protected move semantics.  However the move semantics would have
the same semantics as the copy, and so the extra complication hardly seems worth
the effort.
</p>

<h3>27.6.1.1 - Class template basic_istream</h3>

<p>Add to basic_istream members:</p>

<blockquote><pre>
basic_istream(basic_istream&& rhs);
basic_istream& operator=(basic_istream&& rhs);
void swap(basic_istream&& rhs);
</pre></blockquote>

<p>
The move constructor does not call the move constructor of the base class.
Instead it calls the base class's member <tt>move</tt> function with
<tt>rhs</tt> as an argument.  Additionally it sets the <tt>gcount</tt> of the
<tt>rhs</tt> to zero.
</p>

<p>Change/Add:</p>

<blockquote><pre>
//  lib.istream::extractors character extraction templates:

template&lt;class charT, class traits&gt;
basic_istream&lt;charT,traits&gt;&
operator&gt;&gt;(basic_istream&lt;charT,traits&gt;<del>&</del><ins>&&</ins>, charT&);

template&lt;class traits&gt;
basic_istream&lt;char,traits&gt;&
operator&gt;&gt;(basic_istream&lt;char,traits&gt;<del>&</del><ins>&&</ins>, unsigned char&);

template&lt;class traits&gt;
basic_istream&lt;char,traits&gt;&
operator&gt;&gt;(basic_istream&lt;char,traits&gt;<del>&</del><ins>&&</ins>, signed char&);

template&lt;class charT, class traits&gt;
basic_istream&lt;charT,traits&gt;&
operator&gt;&gt;(basic_istream&lt;charT,traits&gt;<del>&</del><ins>&&</ins>, charT*);

template&lt;class traits&gt;
basic_istream&lt;char,traits&gt;&
operator&gt;&gt;(basic_istream&lt;char,traits&gt;<del>&</del><ins>&&</ins>, unsigned char*);

template&lt;class traits&gt;
basic_istream&lt;char,traits&gt;&
operator&gt;&gt;(basic_istream&lt;char,traits&gt;<del>&</del><ins>&&</ins>, signed char*);

template &lt;class charT, class traits&gt;
void swap(basic_istream&lt;charT, traits&gt;& x, basic_istream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_istream&lt;charT, traits&gt;&& x, basic_istream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_istream&lt;charT, traits&gt;& x, basic_istream&lt;charT, traits&gt;&& y);
</pre></blockquote>

<p>
Note:  There is no backwards compatibility hit on any of these.  They all
currently do not compile when given rvalue streams.
</p>

<h3>27.6.1.5 - Class template basic_iostream</h3>

<p>Add to basic_iostream members:</p>

<blockquote><pre>
basic_iostream(basic_iostream&& rhs);
basic_iostream& operator=(basic_iostream&& rhs);
void swap(basic_iostream&& rhs);
</pre></blockquote>

<p>
All three of the above members will have to take care to only move from (or swap
with) the rhs only once (in an implementation defined manner).
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits&gt;
void swap(basic_iostream&lt;charT, traits&gt;& x, basic_iostream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_iostream&lt;charT, traits&gt;&& x, basic_iostream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_iostream&lt;charT, traits&gt;& x, basic_iostream&lt;charT, traits&gt;&& y);
</pre></blockquote>

<h3>27.6.2.1 - Class template basic_ostream</h3>

<p>Add to basic_ostream members:</p>

<blockquote><pre>
basic_ostream(basic_ostream&& rhs);
basic_ostream& operator=(basic_ostream&& rhs);
void swap(basic_iostream&& rhs);
</pre></blockquote>

<p>
The move constructor does not call the move constructor of the base class.
Instead it calls the base class's member <tt>move</tt> function with
<tt>rhs</tt> as an argument.
</p>

<p>Add:</p>

<blockquote><pre>
//  lib.ostream.inserters.character character inserters
template&lt;class charT, class traits&gt;
basic_ostream&lt;charT,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;charT,traits&gt;&&, charT);

template&lt;class charT, class traits&gt;
basic_ostream&lt;charT,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;charT,traits&gt;&&, char);

//  specialization
template&lt;class traits&gt;
basic_ostream&lt;char,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;char,traits&gt;&&, char);

//  signed and unsigned
template&lt;class traits&gt;
basic_ostream&lt;char,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;char,traits&gt;&&, signed char);

template&lt;class traits&gt;
basic_ostream&lt;char,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;char,traits&gt;&&, unsigned char);

template&lt;class charT, class traits&gt;
basic_ostream&lt;charT,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;charT,traits&gt;&&, const charT*);

template&lt;class charT, class traits&gt;
basic_ostream&lt;charT,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;charT,traits&gt;&&, const char*);

//  partial specializationss
template&lt;class traits&gt;
basic_ostream&lt;char,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;char,traits&gt;&&, const char*);

//   signed and unsigned
template&lt;class traits&gt;
basic_ostream&lt;char,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;char,traits&gt;&&, const signed char*);

template&lt;class traits&gt;
basic_ostream&lt;char,traits&gt;&
operator&lt;&lt;(basic_ostream&lt;char,traits&gt;&&, const unsigned char*);

template &lt;class charT, class traits&gt;
void swap(basic_ostream&lt;charT, traits&gt;& x, basic_ostream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_ostream&lt;charT, traits&gt;&& x, basic_ostream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_ostream&lt;charT, traits&gt;& x, basic_ostream&lt;charT, traits&gt;&& y);
</pre></blockquote>

<p>
Note:  The above simply call their existing lvalue-stream counterparts.  There
is a small backwards compatibility hit on all of these.  The ones taking a char
type currently compile with rvalue streams and resolve to the member inserter
taking an int.  The signatures taking a const charT* currently compile with an
rvalue stream and resolve to the member inserter taking a const
void*.<br>[<i>Example:</i>
</p>

<blockquote><pre>
std::ofstream("log file") &lt;&lt; 'A';
</pre></blockquote>

<p>Today's output: <tt>65</tt> (on an ASCII system)</p>

<p>Proposed output: <tt>A</tt></p>

<blockquote><pre>
----
</pre></blockquote>

<blockquote><pre>
std::ofstream("log file") &lt;&lt; "some text";
</pre></blockquote>

<p>Today's output: <tt>0x000ed1bc</tt> (implementation defined pointer)</p>

<p>Proposed output: <tt>some text</tt></p>

<p>
<i>--end example</i>]
</p>

<p>
In the author's opinion, this is really more of a bug fix, than a backwards
compatibility hit.
</p>

<h3>27.7.1 - Class template basic_stringbuf</h3>

<p>Add to basic_stringbuf members:</p>

<blockquote><pre>
basic_stringbuf(basic_stringbuf&& rhs);
basic_stringbuf& operator=(basic_stringbuf&& rhs);
void swap(basic_stringbuf&& rhs);
</pre></blockquote>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_stringbuf&lt;charT, traits, Allocator&gt;& x,
     basic_stringbuf&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_stringbuf&lt;charT, traits, Allocator&gt;&& x,
     basic_stringbuf&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_stringbuf&lt;charT, traits, Allocator&gt;& x,
     basic_stringbuf&lt;charT, traits, Allocator&gt;&& y);
</pre></blockquote>

<h3>27.7.2 - Class template basic_istringstream</h3>

<p>Add to basic_istringstream members:</p>

<blockquote><pre>
basic_istringstream(basic_istringstream&& rhs);
basic_istringstream& operator=(basic_istringstream&& rhs);
void swap(basic_istringstream&& rhs);
</pre></blockquote>

<p>
After the move constructor moves from the base class and
<tt>basic_stringbuf</tt> member it calls the base class's <tt>set_rdbuf</tt>
member with the address of its <tt>basic_stringbuf</tt>.
</p>

<p>
Note that the member <tt>swap</tt> can simply <tt>swap</tt> the base and
<tt>basic_stringbuf</tt> member.  The base class's <tt>swap</tt> avoids changing
the result of <tt>rdbuf()</tt> which is the correct behavior.
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_istringstream&lt;charT, traits, Allocator&gt;& x,
     basic_istringstream&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_istringstream&lt;charT, traits, Allocator&gt;&& x,
     basic_istringstream&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_istringstream&lt;charT, traits, Allocator&gt;& x,
     basic_istringstream&lt;charT, traits, Allocator&gt;&& y);
</pre></blockquote>

<h3>27.7.3 - Class basic_ostringstream</h3>

<p>Add to basic_ostringstream members:</p>

<blockquote><pre>
basic_ostringstream(basic_ostringstream&& rhs);
basic_ostringstream& operator=(basic_ostringstream&& rhs);
void swap(basic_ostringstream&& rhs);
</pre></blockquote>

<p>
After the move constructor moves from the base class and
<tt>basic_stringbuf</tt> member it calls the base class's <tt>set_rdbuf</tt>
member with the address of its <tt>basic_stringbuf</tt>.
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_ostringstream&lt;charT, traits, Allocator&gt;& x,
     basic_ostringstream&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_ostringstream&lt;charT, traits, Allocator&gt;&& x,
     basic_ostringstream&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_ostringstream&lt;charT, traits, Allocator&gt;& x,
     basic_ostringstream&lt;charT, traits, Allocator&gt;&& y);
</pre></blockquote>

<h3>27.7.4 - Class template basic_stringstream</h3>

<p>Add to basic_stringstream members:</p>

<blockquote><pre>
basic_stringstream(basic_stringstream&& rhs);
basic_stringstream& operator=(basic_stringstream&& rhs);
void swap(basic_stringstream&& rhs);
</pre></blockquote>

<p>
After the move constructor moves from the base class and
<tt>basic_stringbuf</tt> member it calls the base class's <tt>set_rdbuf</tt>
member with the address of its <tt>basic_stringbuf</tt>.
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_stringstream&lt;charT, traits, Allocator&gt;& x,
     basic_stringstream&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_stringstream&lt;charT, traits, Allocator&gt;&& x,
     basic_stringstream&lt;charT, traits, Allocator&gt;& y);

template &lt;class charT, class traits, class Allocator&gt;
void
swap(basic_stringstream&lt;charT, traits, Allocator&gt;& x,
     basic_stringstream&lt;charT, traits, Allocator&gt;&& y);
</pre></blockquote>

<h3>27.8.1.1 - Class template basic_filebuf</h3>

<p>Add to basic_filebuf members:</p>

<blockquote><pre>
basic_filebuf(basic_filebuf&& rhs);
basic_filebuf& operator=(basic_filebuf&& rhs);
void swap(basic_filebuf&& rhs);
</pre></blockquote>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits&gt;
void swap(basic_filebuf&lt;charT, traits&gt;& x, basic_filebuf&lt;charT, traitsr&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_filebuf&lt;charT, traits&gt;&& x, basic_filebuf&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_filebuf&lt;charT, traits&gt;& x, basic_filebuf&lt;charT, traits&gt;&& y);
</pre></blockquote>

<h3>27.8.1.5 - Class template basic_ifstream</h3>

<p>Add to basic_ifstream members:</p>

<blockquote><pre>
basic_ifstream(basic_ifstream&& rhs);
basic_ifstream& operator=(basic_ifstream&& rhs);
void swap(basic_ifstream&& rhs);
</pre></blockquote>

<p>
After the move constructor moves from the base class and <tt>basic_filebuf</tt>
member it calls the base class's <tt>set_rdbuf</tt> member with the address of
its <tt> basic_filebuf </tt>.
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits&gt;
void swap(basic_ifstream&lt;charT, traits&gt;& x, basic_ifstream&lt;charT, traitsr&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_ifstream&lt;charT, traits&gt;&& x, basic_ifstream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_ifstream&lt;charT, traits&gt;& x, basic_ifstream&lt;charT, traits&gt;&& y);
</pre></blockquote>

<h3>27.8.1.8 - Class template basic_ofstream</h3>

<p>Add to basic_ofstream members:</p>

<blockquote><pre>
basic_ofstream(basic_ofstream&& rhs);
basic_ofstream& operator=(basic_ofstream&& rhs);
void swap(basic_ofstream&& rhs);
</pre></blockquote>

<p>
After the move constructor moves from the base class and <tt>basic_filebuf</tt>
member it calls the base class's <tt>set_rdbuf</tt> member with the address of
its <tt> basic_filebuf </tt>.
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits&gt;
void swap(basic_ofstream&lt;charT, traits&gt;& x, basic_ofstream&lt;charT, traitsr&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_ofstream&lt;charT, traits&gt;&& x, basic_ofstream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_ofstream&lt;charT, traits&gt;& x, basic_ofstream&lt;charT, traits&gt;&& y);
</pre></blockquote>

<h3>27.8.1.11 - Class template basic_fstream</h3>

<p>Add to basic_fstream members:</p>

<blockquote><pre>
basic_fstream(basic_fstream&& rhs);
basic_fstream& operator=(basic_fstream&& rhs);
void swap(basic_fstream&& rhs);
</pre></blockquote>

<p>
After the move constructor moves from the base class and <tt>basic_filebuf</tt>
member it calls the base class's <tt>set_rdbuf</tt> member with the address of
its <tt> basic_filebuf </tt>.
</p>

<p>Add:</p>

<blockquote><pre>
template &lt;class charT, class traits&gt;
void swap(basic_fstream&lt;charT, traits&gt;& x, basic_fstream&lt;charT, traitsr&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_fstream&lt;charT, traits&gt;&& x, basic_fstream&lt;charT, traits&gt;& y);

template &lt;class charT, class traits&gt;
void swap(basic_fstream&lt;charT, traits&gt;& x, basic_fstream&lt;charT, traits&gt;&& y);
</pre></blockquote>

<h2>Technical Library Report 1 Impact</h2>

<h3>2.1.2 Class template reference_wrapper</h3>

<blockquote><pre>
template &lt;class T&gt;
class reference_wrapper
    : public unary_function &lt;T1, R&gt;       // see below
    : public binary_function &lt;T1, T2, R&gt;  // see below
{
public :
    // types
    typedef T type;
    typedef see below result_type; // Not always defined

    // construct/copy/destruct
    explicit reference_wrapper (T&);
    reference_wrapper(const reference_wrapper& x);

    // assignment
    reference_wrapper& operator =(const reference_wrapper& x);

    // access
    operator T & () const;
    T& get () const;

    // invocation
    template &lt;class T1, class T2, ..., class TN&gt;
    typename result_of &lt;T(T1, T2, ..., TN)&gt;::type
    operator() (T1<del>&</del><ins>&&</ins>, T2<del>&</del><ins>&&</ins>, ..., TN<del>&</del><ins>&&</ins>) const;
};
</pre></blockquote>

<p>
reference_wrapper will use perfect forwarding.
</p>

<h3>2.2.3 Class template shared_ptr</h3>

<p>Change:</p>

<blockquote><pre>
template &lt;class Y , class D&gt; shared_ptr (Y* p , D<ins>&&</ins> d);
</pre></blockquote>

<p>This eliminates the requirement that the copy constructor of D be nothrow.</p>

<p>Change 2.2.3.1p10:</p>

<p>
Effects: Constructs a <tt>shared_ptr</tt> object that <i>owns</i> the pointer
<tt>p</tt> and <ins>a copy of the</ins> the deleter <tt>d</tt>.
</p>

<p>Add:</p>

<blockquote><pre>
shared_ptr(shared_ptr&& r);
template &lt;class Y&gt; shared_ptr(shared_ptr&lt;Y&gt;&& r);
</pre></blockquote>

<p>Add:</p>

<blockquote><pre>
weak_ptr(weak_ptr&& r);
</pre></blockquote>

<h3>3.3 Requirements</h3>

<p>
Every call wrapper [3.1] shall be <tt>CopyConstructible</tt>. A <i>simple call
wrapper</i> is a call wrapper that is Assignable and whose copy constructor and
assignment operator do not throw exceptions. A <i>forwarding call wrapper</i> is
a call wrapper that can be called with an argument list <tt>t1, t2, ...,
tN</tt><del> where each <tt>ti</tt> is an lvalue. The effect of calling a
forwarding call wrapper with one or more arguments that are rvalues is
implementation defined</del>. [<i>Note:</i> in a typical implementation
forwarding call wrappers have overloaded function call operators of the form
</p>

<blockquote><pre>
template &lt;class T1, class T2, ..., class TN&gt;
R
operator ()(T1<del>&</del><ins>&&</ins> t1 , T2<del>&</del><ins>&&</ins> t2 , ... , TN<del>&</del><ins>&&</ins> tN) <i>cv-qual</i>;
</pre></blockquote>

<h3>3.7.2 Class template function</h3>

<p>Add:</p>

<blockquote><pre>
function(function&&);
function& operator=(function&&);
template&lt;typename F&gt; function(F&&);
template&lt;typename F&gt; function& operator=(F&&);
</pre></blockquote>

<h3>4.2 Header &lt;type_traits&gt; synopsis</h3>

<p>
Remove <tt>add_reference</tt>.  It is now ambiguous, unless renamed to
<tt>add_lvalue_reference</tt> and <tt>add_rvalue_reference</tt>.  Furthermore it
is no longer required with CWG 106 implemented.
</p>

<p>
Add:
</p>

<blockquote><pre>
template &lt;class T&gt; struct remove_reference&lt;T&&&gt; {typedef T type;};
</pre></blockquote>

<h3>4.7 Transformations between types</h3>

<p>
<tt>is_convertible</tt> should test with an rvalue source instead of lvalue
source, and include a <tt>U&&</tt> signature to test against.
</p>

<h3>6.1.3 Class template tuple</h3>

<p>
<tt>tuple</tt> constructors will need to be looked at in a new light.  They will
want to be able to move components into the <tt>tuple</tt> in addition to  of
copy them in as described for <tt>pair</tt>.  Additionally <tt>make_tuple</tt>
will want to take advantage of rvalues.  And of course <tt>tuple</tt> will want
a move constructor and move assignment which does member-wise moving.
</p>

<h3>6.2.2 Class template array</h3>

<p>
It would be good if <tt>array</tt> had a move constructor and move assignment
(to do member-wise moving), but not at the expense of disabling the initializer
syntax of array.  So this will depend upon some other core extension which
addresses initializer syntax for non-PODs.
</p>

<h3>6.3 Unordered associative containers</h3>

<p>
Needs changes analogous to those set forth for the standard ordered associative
containers.
</p>

<h3>7 Regular expressions</h3>

<p>
Add move constructors and move assignment as appropriate.
</p>

<h2>Proposed Libraries</h2>

<h3>A Multi-threading Library for Standard C++</h3>

<p>
Pete Becker has <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1682.html">proposed
a multi-threading library</a> based on the <a
href="http://www.dinkumware.com">Dinkumware</a> implementation, which is also
based on
the <a href="http://www.boost.org">boost threading library</a>.  <a
href="http://www.metrowerks.com">Metrowerks</a> has also shipped a similar
library.  In all three cases, a <tt>scoped_lock</tt> is a non-copyable type
which locks and unlocks <tt>mutex</tt> in a RAII pattern.
</p>

<p>
It is clear that such a <tt>scoped_lock</tt> should not be copied.  However,
movable <tt>scoped_lock</tt>s could have significant utility.  If movable,
<tt>scoped_lock</tt>s could be returned from functions and placed into
containers.
</p>

<p>
[<i>Example:</i>
</p>

<blockquote><pre>
mutex cout_mut;
...
mutex::scoped_lock
get_cout_lock()  <font color="red">// return scoped_lock from function,</font>
                 <font color="red">// even though not copyable</font>
{
    return mutex::scoped_lock(cout_mut, defer_lock);
}
...
vector&lt;mutex::scoped_lock&gt; stdio_locks;
stdio_locks.push_back(get_cout_lock());  <font color="red">// store scoped_lock in container,</font>
                                         <font color="red">// even though not copyable</font>
...
void foo()
{   <font color="red">// access lock for cout_mut from container, even though not copyable</font>
    adapt_lock&lt;mutex::scoped_lock&gt; lock(stdio_locks[0]);
    cout &lt;&lt; "some stuff" &lt;&lt; '\n';
    ...
}
</pre></blockquote>

<p><i>--end example</i>]</p>

<p>
Additionally, if read/write style locks are added to this proposal, conversions
between lock types can become very useful.  For example, <a
href="http://home.twcny.rr.com/hinnant/cpp_extensions/threads_move.html">here</a>
is a study which explores the combination of a <tt>scoped_lock</tt> (also known
as a write lock, same as proposed by Becker), a <tt>sharable_lock</tt> (also
known as a read lock), and an <tt>upgradable_lock</tt> (a lock capable of
sharing locks with a <tt>sharable_lock</tt>, and also transferring exclusive
ownership to a <tt>scoped_lock</tt>).  In this study, move semantics is used to
transfer ownership among the three different types of locks.
</p>

<p>
[<i>Example:</i>
</p>

<blockquote><pre>
struct A
{
    ...
    mutex mut_;
    ...
};

void foo(A& a1, A& a2)
{
    typedef mutex::scoped_lock     write_lock;
    typedef mutex::upgradable_lock read_lock;
    read_lock a2_rlock(a2.mut_, defer_lock);  <font color="red">// a2.mut_ not yet read-locked</font>
    {
    write_lock a1_wlock(a1.mut_, defer_lock); <font color="red">// a1.mut_ not yet write-locked</font>
    lock_both(a1_wlock, a2_rlock);  <font color="red">// a1.mut_ write-locked, a2.mut_ read-locked</font>
                                    <font color="red">// Use of lock_both negates deadlock possibility</font>
    a1 = a2;                        <font color="red">// Assignment is now thread-safe</font>
    }                               <font color="red">// a1.mut_ now unlocked, a2.mut_ still read-locked</font>
    ...
    if (some condition)
    {
        write_lock a2_wlock(<b>move</b>(a2_rlock));  <font color="red">// a2.mut_ upgraded from read-lock to</font>
        a2.modify();                          <font color="red">// write-lock.  a2.modify() is now safe.</font>
    }                    <font color="red">// a2.mut_ now unlocked if some condition was met</font>
}                        <font color="red">// a2.mut_ now (read)unlocked if some condition was not met</font>
</pre></blockquote>

<p><i>--end example</i>]</p>

<p>
Here the function <tt>foo</tt> needs to write-lock <tt>a1</tt>'s mutex but only
read-lock <tt>a2</tt>'s mutex in order to assign from <tt>a2</tt> to
<tt>a1</tt>.  But based on some condition, <tt>foo</tt> may need to later
write-lock <tt>a2</tt> <i>without loosing the existing read-lock</i>.  This is
where an upgradable lock comes in handy.  Using the <tt>move</tt> syntax,
<tt>a2</tt>'s mutex is atomically upgraded from read to write so that non-const
operations can now be carried out on <tt>a2</tt>.  And those operations can
assume that the state read under <tt>a2</tt>'s read-lock is still valid because
the upgrade from read to write lock was atomic.
</p>

<p>
Should the "some condition" not be met, <tt>foo</tt> can share lock ownership of
<tt>a2</tt> with other functions that need only read access to <tt>a2</tt>, thus
improving system throughput.
</p>

<p>
Move semantics has played a role here by allowing the transfer of mutex
ownership among the different locks, with a syntax and semantics that is uniform
with the rest of the C++ world.  Thus non-copyable locks can even be manipulated
by generic move-aware code (such as standard containers and algorithms).
</p>

</body>
</html>
