Skip to content

Commit cfc762f

Browse files
committed
New issue from Zhihao Yuan: "indirect<T> should be convertible to T&"
1 parent 653c7b8 commit cfc762f

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

xml/issue4458.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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&lt;T&gt;</tt> should be convertible to <tt>T&amp;</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&lt;T&gt;</tt> in
15+
Pimpl, <tt>indirect&lt;T&gt;</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&lt;T&gt;</tt> is convertible to <tt>T&amp;</tt>,
18+
certain tasks can be done without meta-programming (e.g., returning the
19+
object of type `T` or <tt>indirect&lt;T&gt;</tt> from a function with a
20+
return type <tt>T&amp;</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&lt;class T, class Allocator = allocator&lt;T&gt;&gt;
36+
class indirect {
37+
public:
38+
[&hellip;]
39+
<i>// <sref ref="[indirect.obs]"/>, observers</i>
40+
<ins>constexpr operator const T&amp; () const &amp; noexcept;
41+
constexpr operator T&amp; () &amp; noexcept;
42+
constexpr operator const T&amp;&amp; () const &amp;&amp; noexcept;
43+
constexpr operator T&amp;&amp; () &amp;&amp; noexcept;</ins>
44+
constexpr const T&amp; operator*() const &amp; noexcept;
45+
constexpr T&amp; operator*() &amp; noexcept;
46+
constexpr const T&amp;&amp; operator*() const &amp;&amp; noexcept;
47+
constexpr T&amp;&amp; operator*() &amp;&amp; noexcept;
48+
constexpr const_pointer operator-&gt;() const noexcept;
49+
constexpr pointer operator-&gt;() noexcept;
50+
[&hellip;]
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&amp; () const &amp; noexcept;
60+
constexpr operator T&amp; () &amp; noexcept;</ins>
61+
constexpr const T&amp; operator*() const &amp; noexcept;
62+
constexpr T&amp; operator*() &amp; 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&amp;&amp; () const &amp;&amp; noexcept;
73+
constexpr operator T&amp;&amp; () &amp;&amp; noexcept;</ins>
74+
constexpr const T&amp;&amp; operator*() const &amp;&amp; noexcept;
75+
constexpr T&amp;&amp; operator*() &amp;&amp; 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

Comments
 (0)