|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | +<meta charset="utf-8"> |
| 5 | +<title>Issue 4210: Issue with cache_latest_view::iterator's reference type </title> |
| 6 | +<meta property="og:title" content="Issue 4210: Issue with cache_latest_view::iterator's reference type "> |
| 7 | +<meta property="og:description" content="C++ library issue. Status: New"> |
| 8 | +<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4210.html"> |
| 9 | +<meta property="og:type" content="website"> |
| 10 | +<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png"> |
| 11 | +<meta property="og:image:alt" content="C++ logo"> |
| 12 | +<style> |
| 13 | + p {text-align:justify} |
| 14 | + li {text-align:justify} |
| 15 | + pre code.backtick::before { content: "`" } |
| 16 | + pre code.backtick::after { content: "`" } |
| 17 | + blockquote.note |
| 18 | + { |
| 19 | + background-color:#E0E0E0; |
| 20 | + padding-left: 15px; |
| 21 | + padding-right: 15px; |
| 22 | + padding-top: 1px; |
| 23 | + padding-bottom: 1px; |
| 24 | + } |
| 25 | + ins {background-color:#A0FFA0} |
| 26 | + del {background-color:#FFA0A0} |
| 27 | + table.issues-index { border: 1px solid; border-collapse: collapse; } |
| 28 | + table.issues-index th { text-align: center; padding: 4px; border: 1px solid; } |
| 29 | + table.issues-index td { padding: 4px; border: 1px solid; } |
| 30 | + table.issues-index td:nth-child(1) { text-align: right; } |
| 31 | + table.issues-index td:nth-child(2) { text-align: left; } |
| 32 | + table.issues-index td:nth-child(3) { text-align: left; } |
| 33 | + table.issues-index td:nth-child(4) { text-align: left; } |
| 34 | + table.issues-index td:nth-child(5) { text-align: center; } |
| 35 | + table.issues-index td:nth-child(6) { text-align: center; } |
| 36 | + table.issues-index td:nth-child(7) { text-align: left; } |
| 37 | + table.issues-index td:nth-child(5) span.no-pr { color: red; } |
| 38 | + @media (prefers-color-scheme: dark) { |
| 39 | + html { |
| 40 | + color: #ddd; |
| 41 | + background-color: black; |
| 42 | + } |
| 43 | + ins { |
| 44 | + background-color: #225522 |
| 45 | + } |
| 46 | + del { |
| 47 | + background-color: #662222 |
| 48 | + } |
| 49 | + a { |
| 50 | + color: #6af |
| 51 | + } |
| 52 | + a:visited { |
| 53 | + color: #6af |
| 54 | + } |
| 55 | + blockquote.note |
| 56 | + { |
| 57 | + background-color: rgba(255, 255, 255, .10) |
| 58 | + } |
| 59 | + } |
| 60 | +</style> |
| 61 | +</head> |
| 62 | +<body> |
| 63 | +<hr> |
| 64 | +<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p> |
| 65 | +<h3 id="4210"><a href="lwg-active.html#4210">4210</a>. Issue with <code>cache_latest_view::<i>iterator</i></code>'s reference type </h3> |
| 66 | +<p><b>Section:</b> 25.7.34.3 <a href="https://wg21.link/range.cache.latest.iterator">[range.cache.latest.iterator]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a> |
| 67 | + <b>Submitter:</b> Hewill Kang <b>Opened:</b> 2025-02-09 <b>Last modified:</b> 2025-02-09</p> |
| 68 | +<p><b>Priority: </b>Not Prioritized |
| 69 | +</p> |
| 70 | +<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p> |
| 71 | +<p><b>Discussion:</b></p> |
| 72 | +<p> |
| 73 | +<code>cache_latest_view::<i>iterator</i></code> can be roughly regarded as an iterator that |
| 74 | +transforms the original iterator's reference, because its reference is <i>always</i> an lvalue |
| 75 | +which is <code>range_reference_t<V>&</code>, even if the original iterator returns |
| 76 | +an rvalue. |
| 77 | +<p/> |
| 78 | +In this case, it seems a bit odd to still specialize <code>iter_move</code> and return the rvalue |
| 79 | +reference type of the original iterator, because the original reference has changed, so the former |
| 80 | +may not form a valid common reference with the original rvalue reference. |
| 81 | +<p/> |
| 82 | +That is, in some rare cases even if the <code>cache_latest_view</code> can be legally constructed, |
| 83 | +it may not be an <code>input_range</code> as <code>indirectly_readable</code> is not satisfied. |
| 84 | +<p/> |
| 85 | +A contrived example could be: |
| 86 | +</p> |
| 87 | +<blockquote><pre> |
| 88 | +struct I { |
| 89 | + using value_type = int; |
| 90 | + using difference_type = int; |
| 91 | + |
| 92 | + struct move_only_ref { |
| 93 | + move_only_ref(const int&); |
| 94 | + move_only_ref(move_only_ref&&) = default; |
| 95 | + }; |
| 96 | + |
| 97 | + move_only_ref operator*() const; |
| 98 | + I& operator++(); |
| 99 | + void operator++(int); |
| 100 | +}; |
| 101 | + |
| 102 | +using R = ranges::cache_latest_view<ranges::subrange<I, unreachable_sentinel_t>>; // ok |
| 103 | + |
| 104 | +static_assert(input_iterator<I>); |
| 105 | +static_assert(ranges::input_range<R>); // failed |
| 106 | +</pre></blockquote> |
| 107 | +<p> |
| 108 | +It's unclear whether we should change the reference type to <code>range_reference_t<V>&&</code> |
| 109 | +to preserve the original ref-qualifiers as much as possible (I don't see any discussion of this option |
| 110 | +in the original paper), or not provide a specialized <code>iter_move</code>, since it's intuitive to have |
| 111 | +the default <code>iter_move</code> return an rvalue when it always returns an lvalue. |
| 112 | +</p> |
| 113 | + |
| 114 | + |
| 115 | +<p id="res-4210"><b>Proposed resolution:</b></p> |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +</body> |
| 122 | +</html> |
0 commit comments