Skip to content

Commit f75def6

Browse files
committed
[P3981] More updates
1 parent 13ff7f7 commit f75def6

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

3981_optional_ref_inplace_vector/optional-ref-inplace-vector.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ if (not sr.empty()) {
124124

125125
This follows the general principle that ranges are simply more convenient for users than iterators, because you only need the one object rather than two.
126126

127+
This API is quite unlike a few algorithms which return an iterator, like `std::find`, where the iterator itself is specifically desired. In this case, the return isn't really conceptually a single iterator — it is very much the range _starting from_ that iterator. Hence, `subrange` is the more appropriate return type.
128+
127129
# Why not do this?
128130

129131
[@P3830R0]{.title} argues that we simply should not make this change, mostly on the basis that it is new. Which, yes, the specific specialization `std::optional<T&>` is new, and it took unnecessarily long to adopt it after `std::optional<T>` was adopted (despite its existence in Boost for decades, and proliferation across many other `optional` implementations). But the notion of an optional reference in general is not new, and we have a lot of experience with it outside of the standard library — and even outside of C++. The Rust standard library returns optional references from many APIs quite liberally.

3981_optional_ref_inplace_vector/p3981r0.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,14 @@ <h1 data-number="3" style="border-bottom:1px solid #cccccc" id="iterator-or-subr
843843
<p>This follows the general principle that ranges are simply more
844844
convenient for users than iterators, because you only need the one
845845
object rather than two.</p>
846+
<p>This API is quite unlike a few algorithms which return an iterator,
847+
like
848+
<code class="sourceCode cpp">std<span class="op">::</span>find</code>,
849+
where the iterator itself is specifically desired. In this case, the
850+
return isn’t really conceptually a single iterator — it is very much the
851+
range <em>starting from</em> that iterator. Hence,
852+
<code class="sourceCode cpp">subrange</code> is the more appropriate
853+
return type.</p>
846854
<h1 data-number="4" style="border-bottom:1px solid #cccccc" id="why-not-do-this"><span class="header-section-number">4</span> Why
847855
not do this?<a href="#why-not-do-this" class="self-link"></a></h1>
848856
<p><span class="title"><span class="citation" data-cites="P3830R0"><a href="https://wg21.link/p3830r0" role="doc-biblioref">[P3830R0]

0 commit comments

Comments
 (0)