Title
views::as_const on ref_view<T> should return ref_view<const T>
Status
c++23
Section
[range.as.const.overview]
Submitter
Tomasz Kami&nacute;ski

Created on 2022-11-03.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:

    [Drafting note: If we have ref_view<V>, when V is constant propagating view (single_view, owning_view), we still can (and should) produce ref_view<V const>. This wording achieves that.]

    -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.2) — Otherwise, if U denotes span<X, Extent> for some type X and some extent Extent, then span<const X, Extent>(E).

    3. (2.?) — Otherwise, if U denotes ref_view<X> for some type X and const X models constant_range, then ref_view(static_cast<const X&>(E.base())).

    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: 2022-11-10.23:33:23

[ Kona 2022-11-08; Move to Ready ]

Date: 2022-11-03.00:00:00

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>>>.

Invoking 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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 10:17:57adminsetmessages: + msg13359
2023-02-13 10:17:57adminsetstatus: voting -> wp
2023-02-06 15:33:48adminsetstatus: ready -> voting
2022-11-10 23:33:23adminsetmessages: + msg13011
2022-11-10 23:33:23adminsetstatus: new -> ready
2022-11-05 15:11:30adminsetmessages: + msg12931
2022-11-03 00:00:00admincreate