File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ <?xml version =' 1.0' encoding =' utf-8' standalone =' no' ?>
2+ <!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+ <issue num =" 4367" status =" New" >
5+ <title >Improve <code >optional< T&> ::or_else</code ></title >
6+ <section >
7+ <sref ref =" [optional.ref.monadic]" />
8+ </section >
9+ <submitter >Hewill Kang</submitter >
10+ <date >07 Sep 2025</date >
11+ <priority >99</priority >
12+
13+ <discussion >
14+ <p >
15+ <code >optional< T&> ::or_else</code > currently returns <code >*<i >val</i ></code > when it has a value,
16+ which calls the <code >optional(U&& )</code > constructor which in turn calls
17+ <code ><i >convert-ref-init-val</i ></code > which in turn calls `addressof`.
18+ <p />
19+ There's no reason to do that. It's much more efficient to call <code >optional< T&> </code >'s
20+ default copy constructor to just copy a pointer.
21+ </p >
22+ </discussion >
23+
24+ <resolution >
25+ <p >
26+ This wording is relative to <paper num =" N5014" />.
27+ </p >
28+
29+ <ol >
30+
31+ <li ><p >Modify <sref ref =" [optional.ref.monadic]" /> as indicated:</p >
32+
33+ <blockquote >
34+ <pre >
35+ template< class F> constexpr optional or_else(F&& f) const;
36+ </pre >
37+ <blockquote >
38+ <p >
39+ -7- <i >Constraints</i >: `F` models `invocable`.
40+ <p />
41+ -8- <i >Mandates</i >: <code >is_same_v< remove_cvref_t< invoke_result_t< F>> , optional> </code > is `true`.
42+ <p />
43+ -9- <i >Effects</i >: Equivalent to:
44+ </p >
45+ <blockquote ><pre >
46+ if (has_value()) {
47+ return *<ins >this</ins ><del ><i >val</i ></del >;
48+ } else {
49+ return std::forward< F> (f)();
50+ }
51+ </pre ></blockquote ></blockquote >
52+ </blockquote >
53+
54+ </li >
55+
56+ </ol ></resolution >
57+
58+ </issue >
You can’t perform that action at this time.
0 commit comments