Created on 2022-11-03.00:00:00 last changed 13 months ago
Proposed resolution:
This wording is relative to N4917.
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:
(2.1) — If views::all_t<T> models constant_range, then views::all(E).
(2.2) — Otherwise, if U denotes span<X, Extent> for some type X and some extent Extent, then span<const X, Extent>(E).
(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())).
(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)).
(2.4) — Otherwise, as_const_view(E).
[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP. ]
[ Kona 2022-11-08; Move to Ready ]
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:43 | admin | set | status: wp -> c++23 |
2023-02-13 10:17:57 | admin | set | messages: + msg13359 |
2023-02-13 10:17:57 | admin | set | status: voting -> wp |
2023-02-06 15:33:48 | admin | set | status: ready -> voting |
2022-11-10 23:33:23 | admin | set | messages: + msg13011 |
2022-11-10 23:33:23 | admin | set | status: new -> ready |
2022-11-05 15:11:30 | admin | set | messages: + msg12931 |
2022-11-03 00:00:00 | admin | create |