|
| 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<class T, class Allocator = allocator<T>> |
| 33 | + class indirect; |
| 34 | +<ins> |
| 35 | +template<class T, class Allocator> |
| 36 | +constexpr void swap(indirect<T, Allocator>& lhs, indirect<T, Allocator>& rhs) noexcept(<i>see below</i>); |
| 37 | +</ins> |
| 38 | +// 20.4.1.10, hash support |
| 39 | +template<class T, class Alloc> struct hash<indirect<T, Alloc>>; |
| 40 | + |
| 41 | +// 20.4.2, class template polymorphic |
| 42 | +template<class T, class Allocator = allocator<T>> |
| 43 | + class polymorphic; |
| 44 | +<ins> |
| 45 | +template<class T, class Allocator> |
| 46 | +constexpr void swap(polymorphic<T, Allocator>& lhs, polymorphic<T, Allocator>& 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& other) noexcept(<i>see below</i>); |
| 57 | +<del>friend constexpr void swap(indirect& lhs, indirect& 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<class T, class Allocator></ins> |
| 66 | +constexpr void swap(indirect<ins><T, Allocator></ins>& lhs, indirect<ins><T, Allocator></ins>& 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& other) noexcept(<i>see below</i>); |
| 77 | +<del>friend constexpr void swap(polymorphic& lhs, polymorphic& 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<class T, class Allocator></ins> |
| 86 | +constexpr void swap(polymorphic<ins><T, Allocator></ins>& lhs, polymorphic<ins><T, Allocator></ins>& 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