Title
borrowed_{iterator,subrange}_t are overspecified
Status
c++23
Section
[range.dangling]
Submitter
Tim Song

Created on 2021-05-12.00:00:00 last changed 13 months ago

Messages

Date: 2021-06-07.16:58:04

Proposed resolution:

This wording is relative to N4885.

  1. Modify [ranges.syn], header <ranges> synopsis, as indicated:

      […]
    namespace std::ranges {
      […]
      // [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 below
          conditional_t<borrowed_range<R>, subrange<iterator_t<R>>, dangling>;
    
      […]
    }
    
  2. Modify [range.dangling] as indicated:

    -1- The tag type dangling is used together with the template aliases borrowed_iterator_t and borrowed_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 model borrowed_range ([range.range]), the return value possibly refers to a range whose lifetime has ended. In such cases, the tag type dangling is returned instead of an iterator or subrange.

    namespace std::ranges {
      struct dangling {
        […]
      };
    }
    

    -2- [Example 1: […] — end example]

    -?- For a type R that models range:

    1. (?.1) — if R models borrowed_range, then borrowed_iterator_t<R> denotes iterator_t<R>, and borrowed_subrange_t<R> denotes subrange<iterator_t<R>>;

    2. (?.2) — otherwise, both borrowed_iterator_t<R> and borrowed_subrange_t<R> denote dangling.

Date: 2021-06-07.00:00:00

[ 2021-06-07 Approved at June 2021 virtual plenary. Status changed: Voting → WP. ]

Date: 2021-05-15.00:00:00

[ 2021-05-20; Reflector poll ]

Set status to Tentatively Ready after seven votes in favour during reflector poll.

Date: 2021-05-12.00:00:00

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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2021-06-07 16:58:04adminsetmessages: + msg11913
2021-06-07 16:58:04adminsetstatus: voting -> wp
2021-05-26 21:11:22adminsetstatus: ready -> voting
2021-05-20 08:55:35adminsetmessages: + msg11829
2021-05-20 08:55:35adminsetstatus: new -> ready
2021-05-15 17:07:53adminsetmessages: + msg11801
2021-05-12 00:00:00admincreate