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.
views::as_const on ref_view<T> should return ref_view<const T>Section: 25.7.22.1 [range.as.const.overview] Status: C++23 Submitter: Tomasz Kamiński Opened: 2022-11-03 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:
For v being a non-const lvalue of type std::vector<int>, views::as_const(v)
produces ref_view<std::vector<int> const>. However, when v is converted to
ref_view by using views::all, views::as_const(views::all(v)) produces
as_const_view<ref_view<std::vector<int>>>.
views::as_const on ref_view<T> should produce ref_view<const T> when
const T models a constant range. This will reduce the number of instantiations, and make a behavior
of views::as_const consistent on references and ref_view to containers.
[Kona 2022-11-08; Move to Ready]
[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:
[Drafting note: If we have
ref_view<V>, whenVis constant propagating view (single_view,owning_view), we still can (and should) produceref_view<V const>. This wording achieves that.]
-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.2) — Otherwise, if
Udenotesspan<X, Extent>for some typeXand some extentExtent, thenspan<const X, Extent>(E).(2.?) — Otherwise, if
Udenotesref_view<X>for some typeXandconst Xmodelsconstant_range, thenref_view(static_cast<const X&>(E.base())).(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).