<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 774: Member swap undefined for most containers</title>
<meta property="og:title" content="Issue 774: Member swap undefined for most containers">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue774.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="774"><a href="lwg-defects.html#774">774</a>. Member <code>swap</code> undefined for most containers</h3>
<p><b>Section:</b> 23 <a href="https://wg21.link/containers">[containers]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Alisdair Meredith <b>Opened:</b> 2008-01-14 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View other</b> <a href="lwg-index-open.html#containers">active issues</a> in [containers].</p>
<p><b>View all other</b> <a href="lwg-index.html#containers">issues</a> in [containers].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
It appears most containers declare but do not define a member-swap
function.
</p>

<p>
This is unfortunate, as all overload the <code>swap</code> algorithm to call the
member-swap function!
(required for <code>swappable</code> guarantees [Table 37] and Container Requirements
[Table 87])
</p>

<p>
Note in particular that Table 87 gives semantics of <code>a.swap(b)</code> as <code>swap(a,b)</code>,
yet for all containers we define <code>swap(a,b)</code> to call <code>a.swap(b)</code> - a circular
definition.
</p>

<p>
A quick survey of clause 23 shows that the following containers provide a
definition for member-swap:
</p>

<blockquote><pre>
array
queue
stack
vector
</pre></blockquote>

<p>
Whereas the following declare it, but do not define the semantics:
</p>

<blockquote><pre>
deque
list
map
multimap
multiset
priority_queue
set
unordered_map
unordered_multi_map
unordered_multi_set
unordered_set
</pre></blockquote>

<p>
Suggested resolution:
</p>
<blockquote><p>
Provide a definition for each of the affected containers...
</p></blockquote>

<p><i>[
Bellevue:
]</i></p>


<blockquote><p>
Move to Open and ask Alisdair to provide wording.
</p></blockquote>

<p><i>[
2009-07 Frankfurt:
]</i></p>


<blockquote><p>
Daniel to provide wording.
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2590.pdf">N2590</a>
is no longer applicable.
</p></blockquote>

<p><i>[
2009-07-28 Daniel provided wording.
]</i></p>


<blockquote>
<ol>
<li>
It assumes that the proposed resolution for <a href="lwg-defects.html#883" title="swap circular definition (Status: C++11)">883</a><sup><a href="https://cplusplus.github.io/LWG/issue883" title="Latest snapshot">(i)</a></sup> is applied,
which breaks the circularity of definition between member
<code>swap</code> and free <code>swap</code>.
</li>

<li>
It uses the notation of the pre-concept allocator trait
<code>allocator_propagation_map</code>, which might be renamed after the
next refactoring phase of generalized allocators.
</li>

<li>
It requires that compare objects, key equal functions and
hash functions in containers are swapped via unqualified free
<code>swap</code> according to <a href="lwg-defects.html#594" title="Disadvantages of defining Swappable in terms of CopyConstructible and Assignable (Status: Resolved)">594</a><sup><a href="https://cplusplus.github.io/LWG/issue594" title="Latest snapshot">(i)</a></sup>.
</li>
</ol>
</blockquote>

<p><i>[
2009-09-30 Daniel adds:
]</i></p>


<blockquote><p>
The outcome of this issue should be considered with the outcome of 
<a href="lwg-defects.html#1198" title="Container adaptor swap: member or non-member? (Status: C++11)">1198</a><sup><a href="https://cplusplus.github.io/LWG/issue1198" title="Latest snapshot">(i)</a></sup> both in style and in content (e.g. bullet 9 suggests to
define the semantic of <code>void priority_queue::swap(priority_queue&amp;)</code> 
in terms of the member <code>swap</code> of the container).
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Looked at, but took no action on as it overlaps too much with
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2982.pdf">N2982</a>.
Waiting for a new draft WP.
</p></blockquote>

<p><i>[
2009-10 Santa Cruz:
]</i></p>


<blockquote><p>
Leave as open. Pablo to provide wording.
</p></blockquote>

<p><i>[
2009-10-26 Pablo updated wording.  Here is the wording he replaced:
]</i></p>


<blockquote class="note">
<ol>
<li>
<p>
Add a new Throws clause just after 99 [allocator.propagation.map]/5:
</p>

<blockquote><pre>
static void swap(Alloc&amp; a, Alloc&amp; b);
</pre>
<blockquote>
<p>
<i>Effects:</i> [..]
</p>

<p>
<ins><i>Throws:</i> Nothing.</ins>
</p>
</blockquote>
</blockquote>
<p><i>[
This exception requirement is added, such that it's combination with the
general container requirements of
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2723.pdf">N2723</a>
[container.requirements.general]/9
make it unambiguously clear that the following descriptions of "swaps the
allocators" have the following meaning: (a) This swap is done by calling
<code>allocator_propagation_map&lt;allocator_type&gt;::swap</code> and (b) This allocator
swap does never propagate an exception
]</i></p>

</li>

<li>
<p>
Change 23.2.7.2 <a href="https://wg21.link/associative.reqmts.except">[associative.reqmts.except]</a>/3 as indicated:
</p>

<blockquote><p>
For associative containers, no <code>swap</code> function throws an exception unless that
exception is thrown by the <del>copy constructor or copy assignment
operator</del>
<ins><code>swap</code></ins> of the container's <code>Pred</code> object<ins>s</ins><del> (if any)</del>.
</p></blockquote>
</li>

<li>
<p>
Change 23.2.8.2 <a href="https://wg21.link/unord.req.except">[unord.req.except]</a>/3 as indicated:
</p>

<blockquote><p>
For unordered associative containers, no <code>swap</code> function throws an
exception unless
that exception is thrown by the <del>copy constructor or copy
assignment operator</del>
<ins><code>swap</code></ins> of the container's <code>Hash</code> or <code>Pred</code> object<ins>s,
respectively</ins><del> (if any)</del>.
</p></blockquote>
</li>

<li>
<p>
Insert a new paragraph just after 23.3 <a href="https://wg21.link/sequences">[sequences]</a>/1:
</p>

<blockquote><p>
<ins>In addition to being available via inclusion of the <code>&lt;algorithm&gt;</code> header,
the <code>swap</code> function templates in 26.7.3 <a href="https://wg21.link/alg.swap">[alg.swap]</a> are also available when the
header <code>&lt;queue&gt;</code> is included.</ins>
</p></blockquote>

<p><i>[
There is a new issue in process that will suggest a minimum header for <code>swap</code>
and <code>move</code>. If this one is provided, this text can be removed and the header
dependency should be added to <code>&lt;queue&gt;</code>
]</i></p>


</li>

<li>
<p>
Add one further clause at the end of 23.3.3.4 <a href="https://wg21.link/array.special">[array.special]</a>:
</p>
<p><i>[This part is added, because otherwise <code>array::swap</code> would otherwise
contradict the
general contract of 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> p. 10 b. 5]</i></p>


<blockquote><p>
<ins><i>Throws:</i> Nothing, unless one of the element-wise <code>swap</code> calls throws
an exception.</ins>
</p></blockquote>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.3.5 <a href="https://wg21.link/deque">[deque]</a>, class template <code>deque</code> synopsis change as indicated:
</p>
<blockquote><pre>
void swap(deque<del>&lt;T,Alloc&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
At the end of 23.3.5.4 <a href="https://wg21.link/deque.modifiers">[deque.modifiers]</a> add as indicated:
</p>

<blockquote><pre>
<ins>void swap(deque&amp; x);</ins>
</pre>
<blockquote>
<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>.</ins>
</p>
<p>
<ins><i>Complexity:</i> Constant time.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In  [forwardlist], class template <code>forward_list</code> synopsis change as indicated:
</p>

<blockquote><pre>
void swap(forward_list<del>&lt;T,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
At the end of  [forwardlist.modifiers] add as indicated:
</p>

<blockquote><pre>
<ins>void swap(forward_list&amp; x);</ins>
</pre>
<blockquote>
<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>.</ins>
</p>
<p>
<ins><i>Complexity:</i> Constant time.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.3.11 <a href="https://wg21.link/list">[list]</a>, class template <code>list</code> synopsis change as indicated:
</p>

<blockquote><pre>
void swap(list<del>&lt;T,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
At the end of 23.3.11.4 <a href="https://wg21.link/list.modifiers">[list.modifiers]</a> add as indicated:
</p>

<blockquote><pre>
<ins>void swap(list&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>.</ins>
</p>

<p>
<ins><i>Complexity:</i> Constant time.</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<p>
At the end of 23.6.4.4 <a href="https://wg21.link/priqueue.members">[priqueue.members]</a> add a new prototype description:
</p>

<blockquote><pre>
<ins>void swap(priority_queue&amp; q);</ins>
</pre>
<blockquote>
<p>
<ins><i>Requires:</i> <code>Compare</code> shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p><i>[
This requirement is added to ensure that even a user defined <code>swap</code>
which is found by ADL for <code>Compare</code> satisfies the <code>Swappable</code> requirements
]</i></p>


<p>
<ins><i>Effects:</i> <code>this-&gt;c.swap(q.c); swap(this-&gt;comp, q.comp);</code></ins>
</p>
<p>
<ins><i>Throws:</i> What and if <code>c.swap(q.c)</code> and <code>swap(comp, q.comp)</code> throws.</ins>
</p>
</blockquote>
</blockquote>
<p><i>[
This part is added, because otherwise <code>priority_queue::swap</code> would otherwise
contradict the general contract of 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> p. 10 b. 5
]</i></p>

</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.3.13 <a href="https://wg21.link/vector">[vector]</a>, class template <code>vector</code> synopsis change as indicated:
</p>

<blockquote><pre>
void swap(vector<del>&lt;T,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
Change 23.3.13.3 <a href="https://wg21.link/vector.capacity">[vector.capacity]</a> p. 8 as indicated:
</p>

<blockquote><pre>
void swap(vector<del>&lt;T,Allocator&gt;</del>&amp; x);
</pre>

<blockquote><p>
<i>Effects:</i> Exchanges the contents and <code>capacity()</code> <ins>and swaps the
allocators</ins> of <code>*this</code> with that of <code>x</code>.
</p></blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<p>
Insert a new paragraph just before 23.4 <a href="https://wg21.link/associative">[associative]</a>/1:
</p>

<blockquote><p>
<ins>In addition to being available via inclusion of the <code>&lt;algorithm&gt;</code> header,
the <code>swap</code> function templates in 26.7.3 <a href="https://wg21.link/alg.swap">[alg.swap]</a> are also available when any of the
headers <code>&lt;map&gt;</code> or <code>&lt;set&gt;</code> are included.</ins>
</p></blockquote>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.4.3 <a href="https://wg21.link/map">[map]</a>, class template <code>map</code> synopsis change as indicated:
</p>

<blockquote><pre>
void swap(map<del>&lt;Key,T,Compare,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
At the end of 23.4.3.4 <a href="https://wg21.link/map.modifiers">[map.modifiers]</a> add as indicated:
</p>

<blockquote><pre>
<ins>void swap(map&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> Compare shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p><i>[
This requirement is added to ensure that even a user defined <code>swap</code>
which is found by ADL for <code>Compare</code> satisfies the <code>Swappable</code>
requirements
]</i></p>


<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the comparison objects
of <code>*this</code> and <code>x</code>.</ins>
</p>

<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.4.4 <a href="https://wg21.link/multimap">[multimap]</a>, class template <code>multimap</code> synopsis change as indicated:
</p>

<blockquote><pre>
void swap(multimap<del>&lt;Key,T,Compare,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
At the end of 23.4.4.3 <a href="https://wg21.link/multimap.modifiers">[multimap.modifiers]</a> add as indicated:
</p>

<blockquote><pre>
<ins>void swap(multimap&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> Compare shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>
<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the comparison objects
of <code>*this</code> and <code>x</code>.</ins>
</p>
<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.4.6 <a href="https://wg21.link/set">[set]</a>, class template <code>set</code> synopsis change as indicated:
</p>

<blockquote><pre>
void swap(set<del>&lt;Key,Compare,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
After section 23.4.6.2 <a href="https://wg21.link/set.cons">[set.cons]</a> add a new section <ins><code>set</code> modifiers
23.4.6.4 <a href="https://wg21.link/set.modifiers">[set.modifiers]</a></ins>
and add the following paragraphs:
</p>

<blockquote><pre>
<ins>void swap(set&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> Compare shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the comparison objects
of <code>*this</code> and <code>x</code>.</ins>
</p>

<p>
<ins>Complexity: Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<ol style="list-style-type:lower-alpha">
<li>
<p>
In 23.4.7 <a href="https://wg21.link/multiset">[multiset]</a>, class template <code>multiset</code> synosis, change as indicated:
</p>

<blockquote><pre>
void swap(multiset<del>&lt;Key,Compare,Allocator&gt;</del>&amp;);
</pre></blockquote>
</li>

<li>
<p>
After section 23.4.7.2 <a href="https://wg21.link/multiset.cons">[multiset.cons]</a> add a new section <ins><code>multiset</code> modifiers
 [multiset.modifiers]</ins> and add the following paragraphs:
</p>

<blockquote><pre>
<ins>void swap(multiset&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> Compare shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p>
<ins><i>Effects:</i> Exchanges the contents and swaps the allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the comparison objects
of <code>*this</code> and <code>x</code>.</ins>
</p>

<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>
</ol>
</li>

<li>
<p>
Insert a new paragraph just before 23.5 <a href="https://wg21.link/unord">[unord]</a> p. 1:
</p>

<blockquote><p>
<ins>In addition to being available via inclusion of the <code>&lt;algorithm&gt;</code> header,
the <code>swap</code> function templates in 26.7.3 <a href="https://wg21.link/alg.swap">[alg.swap]</a> are also available when any of the
headers <code>&lt;unordered_map&gt;</code> or <code>&lt;unordered_set&gt;</code> are included.</ins>
</p></blockquote>

</li>

<li>
<p>
After section 23.5.3.3 <a href="https://wg21.link/unord.map.elem">[unord.map.elem]</a> add a new section <ins>unordered_map
modifiers 23.5.3.4 <a href="https://wg21.link/unord.map.modifiers">[unord.map.modifiers]</a></ins> and add the following paragraphs:
</p>

<blockquote><pre>
<ins>void swap(unordered_map&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> <code>Hash</code> and <code>Pred</code> shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p><i>[
This requirement is added to ensure that even a user defined <code>swap</code>
which is found by ADL for <code>Hash</code> and <code>Pred</code> satisfies the <code>Swappable</code>
requirements
]</i></p>


<p>
<ins><i>Effects:</i> Exchanges the contents and hash policy and swaps the allocators of <code>*this</code> 
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the <code>Pred</code> objects
and an unqualified <code>swap</code> of the <code>Hash</code> objects of <code>*this</code> and <code>x</code>.</ins>
</p>

<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
After section 23.5.4.2 <a href="https://wg21.link/unord.multimap.cnstr">[unord.multimap.cnstr]</a> add a new section
<ins>unordered_multimap
modifiers 23.5.4.3 <a href="https://wg21.link/unord.multimap.modifiers">[unord.multimap.modifiers]</a></ins> and add the following paragraphs:
</p>

<blockquote><pre>
<ins>void swap(unordered_multimap&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> <code>Hash</code> and <code>Pred</code> shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p>
<ins><i>Effects:</i> Exchanges the contents and hash policy and swaps the
allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the <code>Pred</code> objects
and an unqualified <code>swap</code> of the <code>Hash</code> objects of <code>*this</code> and <code>x</code></ins>
</p>
<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
After section 23.5.6.2 <a href="https://wg21.link/unord.set.cnstr">[unord.set.cnstr]</a> add a new section
<ins>unordered_set modifiers
23.5.6.4 <a href="https://wg21.link/unord.set.modifiers">[unord.set.modifiers]</a></ins> and add the following paragraphs:
</p>

<blockquote><pre>
<ins>void swap(unordered_set&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> <code>Hash</code> and <code>Pred</code> shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p>
<ins><i>Effects:</i> Exchanges the contents and hash policy and swaps the
allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the <code>Pred</code> objects
and an unqualified <code>swap</code> of the <code>Hash</code> objects of <code>*this</code> and <code>x</code></ins>
</p>

<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>

<li>
<p>
After section 23.5.7.2 <a href="https://wg21.link/unord.multiset.cnstr">[unord.multiset.cnstr]</a> add a new section
<ins>unordered_multiset
modifiers  [unord.multiset.modifiers]</ins> and add the following paragraphs:
</p>

<blockquote><pre>
<ins>void swap(unordered_multiset&amp; x);</ins>
</pre>

<blockquote>
<p>
<ins><i>Requires:</i> <code>Hash</code> and <code>Pred</code> shall satisfy the <code>Swappable</code> requirements
( [swappable]).</ins>
</p>

<p>
<ins><i>Effects:</i> Exchanges the contents and hash policy and swaps the
allocators of <code>*this</code>
with that of <code>x</code>, followed by an unqualified <code>swap</code> of the <code>Pred</code> objects
and an unqualified <code>swap</code> of the <code>Hash</code> objects of <code>*this</code> and <code>x</code></ins>
</p>
<p>
<ins><i>Complexity:</i> Constant time</ins>
</p>
</blockquote>
</blockquote>
</li>

</ol>

</blockquote>

<p><i>[
2009-10-30 Pablo and Daniel updated wording.
]</i></p>


<p><i>[
2010 Pittsburgh:  Ready for Pittsburgh.
]</i></p>




<p id="res-774"><b>Proposed resolution:</b></p>

<p><i>[
This resolution is based on the September 2009 WP,
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2960.pdf">N2960</a>,
except that it assumes that
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2982.pdf">N2982</a>
and issues <a href="lwg-defects.html#883" title="swap circular definition (Status: C++11)">883</a><sup><a href="https://cplusplus.github.io/LWG/issue883" title="Latest snapshot">(i)</a></sup> and <a href="lwg-closed.html#1232" title="Still swap's with rvalue-references (Status: NAD Editorial)">1232</a><sup><a href="https://cplusplus.github.io/LWG/issue1232" title="Latest snapshot">(i)</a></sup> have already been applied.  Note in
particular that Table 91 in
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2960.pdf">N2960</a>
is refered to as Table 90 because
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2982.pdf">N2982</a>
removed the old Table 90.  This resolution also addresses issue <a href="lwg-defects.html#431" title="Swapping containers with unequal allocators (Status: Resolved)">431</a><sup><a href="https://cplusplus.github.io/LWG/issue431" title="Latest snapshot">(i)</a></sup>.
]</i></p>

<p>
In 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>, replace the a.swap(b) row in table 90,
"container requirements" (was table 91 before the application of 
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2982.pdf">N2982</a> 
to the WP):
</p>
<blockquote>
<table border="1">
  <tr>
    <td><code>a.swap(b)</code></td>
    <td><code>void</code></td>
    <td>&nbsp;&nbsp;&nbsp;</td>
    <td><code><del>swap(a,b)</del><ins>Exchange the contents of <code>a</code> and <code>b</code>.</ins></code></td>
    <td>(Note A)</td>
  </tr>
  <tr>
    <td><ins><code>swap(a,b)</code></ins></td>
    <td><ins><code>void</code></ins></td>
    <td><code>&nbsp;&nbsp;&nbsp;</code></td>
    <td><ins><code>a.swap(b)</code></ins></td>
    <td><ins>(Note A)</ins></td>
  </tr>
</table>
</blockquote>
<p>
Modify the notes immediately following Table 90 in
23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a> as follows (The wording below is after the
application of <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2982.pdf">N2982</a> 
to <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2960.pdf">N2960</a>.  The 
editor might also want to combine Notes A and B into one.):
</p>
<blockquote><p>
Notes: the algorithms<del> swap(),</del> equal() and lexicographical_compare()
are defined in Clause 25.  Those entries marked "(Note A)" or "(Note B)"
<del>should</del> have <ins>linear complexity for array and</ins> constant
complexity <ins>for all other standard containers</ins>.
</p></blockquote>
<p>
In 23.2.2 <a href="https://wg21.link/container.requirements.general">[container.requirements.general]</a>, before paragraph 8, add:
</p>
<blockquote><p><ins>
The expression <code>a.swap(b)</code>, for containers <code>a</code>
and <code>b</code> of a standard container type other than <code>array</code>,
exchanges the values of <code>a</code> and <code>b</code> without invoking any
move, copy, or swap operations on the individual container elements.
Any <code>Compare</code>, <code>Pred</code>, or <code>Hash</code> function
objects belonging to <code>a</code> and <code>b</code> shall be
<code>swappable</code> and are exchanged by unqualified calls
to non-member <code>swap</code>.  If
<code>allocator_traits&lt;allocator_type&gt;::propagate_on_container_swap::value
== true</code>, then the allocators of <code>a</code> and <code>b</code> are
also exchanged using an unqualified call to non-member <code>swap</code>.
Otherwise, the behavior is undefined unless <code>a.get_allocator() ==
b.get_allocator()</code>.  Each iterator refering to an element in one
container before the swap shall refer to the same element in the other
container after the swap.  It is unspecified whether an iterator with
value <code>a.end()</code> before the swap will have
value <code>b.end()</code> after the swap.  In addition to being available via
inclusion of the <code>&lt;utility&gt;</code> header, the <code>swap</code>
function template in 26.7.3 <a href="https://wg21.link/alg.swap">[alg.swap]</a> is also available within the definition of
every standard container's <code>swap</code> function.
</ins></p></blockquote>
<p><i>[
Note to the editor: Paragraph 2 starts with a sentence fragment,
clearly from an editing or source-control error.
]</i></p>

<p>
Modify 23.2.7.2 <a href="https://wg21.link/associative.reqmts.except">[associative.reqmts.except]</a> as follows:
</p>
<blockquote>
<p>
<b>23.2.4.1 Exception safety guarantees 23.2.7.2 <a href="https://wg21.link/associative.reqmts.except">[associative.reqmts.except]</a></b>
</p>
<p>
For associative containers, no <code>clear()</code> function throws an
exception. <code>erase(k)</code> does not throw an exception unless that
exception is thrown by the
container's <code><del>Pred</del><ins>Compare</ins></code> object (if any).
</p>
<p>
For associative containers, if an exception is thrown by any operation from
within an <code>insert()</code> function inserting a single element,
the <code>insert()</code> function has no effect.
</p>
<p>
For associative containers, no <code>swap</code> function throws an exception
unless that exception is thrown by the <del>copy constructor
or copy assignment operator</del><ins>swap</ins> of the
container's <code><del>Pred</del><ins>Compare</ins></code> object (if any).
</p></blockquote>
<p>
Modify 23.2.8.2 <a href="https://wg21.link/unord.req.except">[unord.req.except]</a>, paragraph 3 as follows:
</p>
<blockquote><p>
For unordered associative containers, no <code>swap</code> function throws an
exception unless that exception is thrown by the <del>copy constructor or copy
assignment operator</del><ins>swap</ins> of the container's <code>Hash</code>
or <code>Pred</code> object (if any).
</p></blockquote>
<p>
Modify section 23.3.3.4 <a href="https://wg21.link/array.special">[array.special]</a>:
</p>
<blockquote>
<p>
<b>array specialized algorithms 23.3.3.4 <a href="https://wg21.link/array.special">[array.special]</a></b>
</p>
<p>
<code>template &lt;class T, size_t N&gt; void swap(array&lt;T,N&gt;&amp; x,array&lt;T,N&gt;&amp; y);</code>
</p>
<blockquote>
<p>
<i>Effects:</i> <code><del>swap_ranges(x.begin(), x.end(), y.begin() );</del><ins>x.swap(y);</ins></code>
</p>
</blockquote>
</blockquote>
<p>
Add a new section after  [array.fill] (Note to the editor: array::fill make use
of a concept requirement that must be removed or changed to text.):
</p>
<blockquote>
<p>
<ins><b>array::swap [array.swap]</b></ins>
</p>
<p>
<ins><code>void swap(array&amp; y);</code></ins>
</p>
<blockquote>
<p><ins>
<i>Effects:</i> <code>swap_ranges(this-&gt;begin(), this-&gt;end(), y.begin() );</code>
</ins></p>
<p><ins>
<i>Throws:</i> Nothing unless one of the element-wise swap calls throws an
exception.
</ins></p>
<p><ins>
[<i>Note</i>: Unlike other containers' <code>swap</code> functions,
<code>array::swap</code> takes linear, not constant, time, may exit via an
exception, and does not cause iterators to become associated with the other
container. &mdash; <i>end note</i>]
</ins></p>
</blockquote>
</blockquote>

<p>
Insert a new paragraph just after 23.6 <a href="https://wg21.link/container.adaptors">[container.adaptors]</a>/1:
</p>
<blockquote><p><ins>
For container adaptors, no <code>swap</code> function throws an exception
unless that exception is thrown by the swap of the
adaptor's <code>Container</code> or <code>Compare</code> object (if any).
</ins></p></blockquote>












</body>
</html>
