|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4210" status="New"> |
| 5 | +<title>Issue with <tt>cache_latest_view::<i>iterator</i></tt>'s reference type </title> |
| 6 | +<section><sref ref="[range.cache.latest.iterator]"/></section> |
| 7 | +<submitter>Hewill Kang</submitter> |
| 8 | +<date>09 Feb 2025</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +<code>cache_latest_view::<i>iterator</i></code> can be roughly regarded as an iterator that |
| 14 | +transforms the original iterator's reference, because its reference is <i>always</i> an lvalue |
| 15 | +which is <code>range_reference_t<V>&</code>, even if the original iterator returns |
| 16 | +an rvalue. |
| 17 | +<p/> |
| 18 | +In this case, it seems a bit odd to still specialize <code>iter_move</code> and return the rvalue |
| 19 | +reference type of the original iterator, because the original reference has changed, so the former |
| 20 | +may not form a valid common reference with the original rvalue reference. |
| 21 | +<p/> |
| 22 | +That is, in some rare cases even if the <code>cache_latest_view</code> can be legally constructed, |
| 23 | +it may not be an <code>input_range</code> as <code>indirectly_readable</code> is not satisfied. |
| 24 | +<p/> |
| 25 | +A contrived example could be: |
| 26 | +</p> |
| 27 | +<blockquote><pre> |
| 28 | +struct I { |
| 29 | + using value_type = int; |
| 30 | + using difference_type = int; |
| 31 | + |
| 32 | + struct move_only_ref { |
| 33 | + move_only_ref(const int&); |
| 34 | + move_only_ref(move_only_ref&&) = default; |
| 35 | + }; |
| 36 | + |
| 37 | + move_only_ref operator*() const; |
| 38 | + I& operator++(); |
| 39 | + void operator++(int); |
| 40 | +}; |
| 41 | + |
| 42 | +using R = ranges::cache_latest_view<ranges::subrange<I, unreachable_sentinel_t>>; // ok |
| 43 | + |
| 44 | +static_assert(input_iterator<I>); |
| 45 | +static_assert(ranges::input_range<R>); // failed |
| 46 | +</pre></blockquote> |
| 47 | +<p> |
| 48 | +It's unclear whether we should change the reference type to <code>range_reference_t<V>&&</code> |
| 49 | +to preserve the original ref-qualifiers as much as possible (I don't see any discussion of this option |
| 50 | +in the original paper), or not provide a specialized <code>iter_move</code>, since it's intuitive to have |
| 51 | +the default <code>iter_move</code> return an rvalue when it always returns an lvalue. |
| 52 | +</p> |
| 53 | +</discussion> |
| 54 | + |
| 55 | +<resolution> |
| 56 | +</resolution> |
| 57 | + |
| 58 | +</issue> |
0 commit comments