Skip to content

Commit 2399890

Browse files
committed
New issue: swap overloads for indirect and polymorphic only found by ADL
1 parent 2c57b78 commit 2399890

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

xml/issue4250.xml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4250" status="New">
5+
<title>`swap` overloads for `indirect` and `polymorphic` only found by ADL</title>
6+
<section><sref ref="[indirect.swap]"/></section>
7+
<section><sref ref="[polymorphic.swap]"/></section>
8+
<submitter>Jonathan Wakely</submitter>
9+
<date>01 May 2025</date>
10+
<priority>99</priority>
11+
12+
<discussion>
13+
<p>
14+
The non-member `swap` overloads for `std::indirect` and `std::polymorphic`
15+
are defined as hidden friends, so are only available via ADL.
16+
This means that calling `std::swap(i1, i2)` will always use the generic
17+
`std::swap` instead of the custom overload for `std::indirect`.
18+
</p>
19+
</discussion>
20+
21+
<resolution>
22+
<p>
23+
This wording is relative to <paper num="N5008"/>.
24+
</p>
25+
<ol>
26+
27+
<li><p>Modify <sref ref="[memory.syn]"/> as indicated:</p>
28+
29+
<blockquote>
30+
<pre><code>
31+
// 20.4.1, class template indirect
32+
template&lt;class T, class Allocator = allocator&lt;T&gt;&gt;
33+
class indirect;
34+
<ins>
35+
template&lt;class T, class Allocator&gt;
36+
constexpr void swap(indirect&lt;T, Allocator&gt;&amp; lhs, indirect&lt;T, Allocator&gt;&amp; rhs) noexcept(<i>see below</i>);
37+
</ins>
38+
// 20.4.1.10, hash support
39+
template&lt;class T, class Alloc&gt; struct hash&lt;indirect&lt;T, Alloc&gt;&gt;;
40+
41+
// 20.4.2, class template polymorphic
42+
template&lt;class T, class Allocator = allocator&lt;T&gt;&gt;
43+
class polymorphic;
44+
<ins>
45+
template&lt;class T, class Allocator&gt;
46+
constexpr void swap(polymorphic&lt;T, Allocator&gt;&amp; lhs, polymorphic&lt;T, Allocator&gt;&amp; rhs) noexcept(<i>see below</i>);
47+
</ins>
48+
</code></pre>
49+
</blockquote>
50+
</li>
51+
52+
<li><p>Modify <sref ref="[indirect.syn]"/> as indicated:</p>
53+
<blockquote>
54+
<pre><code>
55+
// 20.4.1.7, swap
56+
constexpr void swap(indirect&amp; other) noexcept(<i>see below</i>);
57+
<del>friend constexpr void swap(indirect&amp; lhs, indirect&amp; rhs) noexcept(<i>see below</i>);</del>
58+
</code></pre>
59+
</blockquote>
60+
</li>
61+
62+
<li><p>Modify <sref ref="[indirect.swap]"/> as indicated:</p>
63+
<blockquote>
64+
<pre><code>
65+
<ins>template&lt;class T, class Allocator&gt;</ins>
66+
constexpr void swap(indirect<ins>&lt;T, Allocator&gt;</ins>&amp; lhs, indirect<ins>&lt;T, Allocator&gt;</ins>&amp; rhs) noexcept(noexcept(lhs.swap(rhs)));
67+
</code></pre>
68+
<blockquote>-3- <i>Effects</i>: Equivalent to `lhs.swap(rhs)`.</blockquote>
69+
</blockquote>
70+
</li>
71+
72+
<li><p>Modify <sref ref="[polymorphic.syn]"/> as indicated:</p>
73+
<blockquote>
74+
<pre><code>
75+
// 20.4.2.7, swap
76+
constexpr void swap(polymorphic&amp; other) noexcept(<i>see below</i>);
77+
<del>friend constexpr void swap(polymorphic&amp; lhs, polymorphic&amp; rhs) noexcept(<i>see below</i>);</del>
78+
</code></pre>
79+
</blockquote>
80+
</li>
81+
82+
<li><p>Modify <sref ref="[polymorphic.swap]"/> as indicated:</p>
83+
<blockquote>
84+
<pre><code>
85+
<ins>template&lt;class T, class Allocator&gt;</ins>
86+
constexpr void swap(polymorphic<ins>&lt;T, Allocator&gt;</ins>&amp; lhs, polymorphic<ins>&lt;T, Allocator&gt;</ins>&amp; rhs) noexcept(noexcept(lhs.swap(rhs)));
87+
</code></pre>
88+
<blockquote>-3- <i>Effects</i>: Equivalent to `lhs.swap(rhs)`.</blockquote>
89+
</blockquote>
90+
</li>
91+
92+
</ol>
93+
94+
</resolution>
95+
96+
</issue>

0 commit comments

Comments
 (0)