|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4458" status="New"> |
| 5 | +<title><tt>indirect<T></tt> should be convertible to <tt>T&</tt></title> |
| 6 | +<section><sref ref="[indirect.obs]"/></section> |
| 7 | +<submitter>Zhihao Yuan</submitter> |
| 8 | +<date>05 Nov 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<b>Addresses <a href="https://github.com/cplusplus/nbballot/issues/719">US 77-140</a></b> |
| 13 | +<p> |
| 14 | +In addition to serving as a better <tt>unique_ptr<T></tt> in |
| 15 | +Pimpl, <tt>indirect<T></tt> can also appear as a drop-in |
| 16 | +replacement for `T` when `T` may conditionally be an incomplete type. |
| 17 | +In which case, if <tt>indirect<T></tt> is convertible to <tt>T&</tt>, |
| 18 | +certain tasks can be done without meta-programming (e.g., returning the |
| 19 | +object of type `T` or <tt>indirect<T></tt> from a function with a |
| 20 | +return type <tt>T&</tt>). |
| 21 | +</p> |
| 22 | +</discussion> |
| 23 | + |
| 24 | +<resolution> |
| 25 | +<p> |
| 26 | +This wording is relative to <paper num="N5014"/>. |
| 27 | +</p> |
| 28 | + |
| 29 | +<ol> |
| 30 | +<li><p>Modify <sref ref="[indirect.syn]"/>, as indicated:</p> |
| 31 | + |
| 32 | +<blockquote> |
| 33 | +<pre> |
| 34 | +namespace std { |
| 35 | + template<class T, class Allocator = allocator<T>> |
| 36 | + class indirect { |
| 37 | + public: |
| 38 | + […] |
| 39 | + <i>// <sref ref="[indirect.obs]"/>, observers</i> |
| 40 | + <ins>constexpr operator const T& () const & noexcept; |
| 41 | + constexpr operator T& () & noexcept; |
| 42 | + constexpr operator const T&& () const && noexcept; |
| 43 | + constexpr operator T&& () && noexcept;</ins> |
| 44 | + constexpr const T& operator*() const & noexcept; |
| 45 | + constexpr T& operator*() & noexcept; |
| 46 | + constexpr const T&& operator*() const && noexcept; |
| 47 | + constexpr T&& operator*() && noexcept; |
| 48 | + constexpr const_pointer operator->() const noexcept; |
| 49 | + constexpr pointer operator->() noexcept; |
| 50 | + […] |
| 51 | +</pre> |
| 52 | +</blockquote> |
| 53 | +</li> |
| 54 | + |
| 55 | +<li><p>Modify <sref ref="[indirect.obs]"/>, as indicated:</p> |
| 56 | + |
| 57 | +<blockquote> |
| 58 | +<pre> |
| 59 | +<ins>constexpr operator const T& () const & noexcept; |
| 60 | +constexpr operator T& () & noexcept;</ins> |
| 61 | +constexpr const T& operator*() const & noexcept; |
| 62 | +constexpr T& operator*() & noexcept; |
| 63 | +</pre> |
| 64 | +<blockquote> |
| 65 | +<p> |
| 66 | +-1- <i>Preconditions</i>: `*this` is not valueless. |
| 67 | +<p/> |
| 68 | +-2- <i>Returns</i>: <tt>*<i>p</i></tt>. |
| 69 | +</p> |
| 70 | +</blockquote> |
| 71 | +<pre> |
| 72 | +<ins>constexpr operator const T&& () const && noexcept; |
| 73 | +constexpr operator T&& () && noexcept;</ins> |
| 74 | +constexpr const T&& operator*() const && noexcept; |
| 75 | +constexpr T&& operator*() && noexcept; |
| 76 | +</pre> |
| 77 | +<blockquote> |
| 78 | +<p> |
| 79 | +-3- <i>Preconditions</i>: `*this` is not valueless. |
| 80 | +<p/> |
| 81 | +-4- <i>Returns</i>: <tt>std::move(*<i>p</i>)</tt>. |
| 82 | +</p> |
| 83 | +</blockquote> |
| 84 | +</blockquote> |
| 85 | +</li> |
| 86 | + |
| 87 | +</ol> |
| 88 | +</resolution> |
| 89 | + |
| 90 | +</issue> |
0 commit comments