views::as_const on empty_view<T> should return empty_view<const T>Section: 25.7.22.1 [range.as.const.overview] Status: C++23 Submitter: Hewill Kang Opened: 2023-01-06 Last modified: 2023-11-22
Priority: Not Prioritized
View all other issues in [range.as.const.overview].
View all issues with C++23 status.
Discussion:
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.
[2023-02-01; Reflector poll]
Set status to Tentatively Ready after eight votes in favour during reflector poll.
[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N4917.
Modify 25.7.22.1 [range.as.const.overview] as indicated:
-2- The name
views::as_constdenotes a range adaptor object (25.7.2 [range.adaptor.object]). LetEbe an expression, letTbedecltype((E)), and letUberemove_cvref_t<T>. The expressionviews::as_const(E)is expression-equivalent to:
(2.1) — If
views::all_t<T>modelsconstant_range, thenviews::all(E).(2.?) — Otherwise, if
Udenotesempty_view<X>for some typeX, thenauto(views::empty<const X>).(2.2) — Otherwise, if
Udenotesspan<X, Extent>for some typeXand some extentExtent, thenspan<const X, Extent>(E).(2.3) — Otherwise, if
Eis an lvalue,const Umodelsconstant_range, andUdoes not modelview, thenref_view(static_cast<const U&>(E)).(2.4) — Otherwise,
as_const_view(E).