This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.
borrowed_{iterator,subrange}_t
are overspecifiedSection: 25.5.5 [range.dangling] Status: C++23 Submitter: Tim Song Opened: 2021-05-12 Last modified: 2023-11-22
Priority: Not Prioritized
View all issues with C++23 status.
Discussion:
As discussed in P1715R0,
there are ways to implement something equivalent to std::conditional_t
that are better for compile times. However, borrowed_{iterator,subrange}_t
are currently specified to use conditional_t
, and this appears to be
user-observable due to the transparency of alias templates. We should simply
specify the desired result and leave the actual definition to the implementation.
[2021-05-20; Reflector poll]
Set status to Tentatively Ready after seven votes in favour during reflector poll.
[2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4885.
Modify 25.2 [ranges.syn], header <ranges>
synopsis, as indicated:
[…] namespace std::ranges { […] // 25.5.5 [range.dangling], dangling iterator handling struct dangling; template<range R> using borrowed_iterator_t = see belowconditional_t<borrowed_range<R>, iterator_t<R>, dangling>; template<range R> using borrowed_subrange_t = see belowconditional_t<borrowed_range<R>, subrange<iterator_t<R>>, dangling>; […] }
Modify 25.5.5 [range.dangling] as indicated:
-1- The tag type
dangling
is used together with the template aliasesborrowed_iterator_t
andborrowed_subrange_t
. When an algorithm that typically returns an iterator into, or a subrange of, a range argument is called with an rvalue range argument that does not modelborrowed_range
(25.4.2 [range.range]), the return value possibly refers to a range whose lifetime has ended. In such cases, the tag typedangling
is returned instead of an iterator or subrange.namespace std::ranges { struct dangling { […] }; }-2- [Example 1: […] — end example]
-?- For a typeR
that modelsrange
:
(?.1) — if
R
modelsborrowed_range
, thenborrowed_iterator_t<R>
denotesiterator_t<R>
, andborrowed_subrange_t<R>
denotessubrange<iterator_t<R>>
;(?.2) — otherwise, both
borrowed_iterator_t<R>
andborrowed_subrange_t<R>
denotedangling
.