Title
views::as_const on empty_view<T> should return empty_view<const T>
Status
c++23
Section
[range.as.const.overview]
Submitter
Hewill Kang

Created on 2023-01-06.00:00:00 last changed 12 months ago

Messages

Date: 2023-02-13.10:17:57

Proposed resolution:

This wording is relative to N4917.

  1. Modify [range.as.const.overview] as indicated:

    -2- The name views::as_const denotes a range adaptor object ([range.adaptor.object]). Let E be an expression, let T be decltype((E)), and let U be remove_cvref_t<T>. The expression views::as_const(E) is expression-equivalent to:

    1. (2.1) — If views::all_t<T> models constant_range, then views::all(E).

    2. (2.?) — Otherwise, if U denotes empty_view<X> for some type X, then auto(views::empty<const X>).

    3. (2.2) — Otherwise, if U denotes span<X, Extent> for some type X and some extent Extent, then span<const X, Extent>(E).

    4. (2.3) — Otherwise, if E is an lvalue, const U models constant_range, and U does not model view, then ref_view(static_cast<const U&>(E)).

    5. (2.4) — Otherwise, as_const_view(E).

Date: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP. ]

Date: 2023-02-15.00:00:00

[ 2023-02-01; Reflector poll ]

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

Date: 2023-01-06.00:00:00

Currently, applying views::as_const to an empty_view<int> will result in an as_const_view<empty_view<int>>, and its iterator type will be basic_const_iterator<int*>.

This amount of instantiation is not desirable for such a simple view, in which case simply returning empty_view<const int> should be enough.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 10:17:57adminsetmessages: + msg13370
2023-02-13 10:17:57adminsetstatus: voting -> wp
2023-02-06 15:33:48adminsetstatus: ready -> voting
2023-02-01 20:35:14adminsetmessages: + msg13244
2023-02-01 20:35:14adminsetstatus: new -> ready
2023-01-06 16:24:01adminsetmessages: + msg13187
2023-01-06 00:00:00admincreate