Issue 3847: ranges::to can still return views (original) (raw)
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.
3847. ranges::to can still return views
Section: 25.5.7.2 [range.utility.conv.to], 25.5.7.3 [range.utility.conv.adaptors] Status: C++23 Submitter: Hewill Kang Opened: 2023-01-06 Last modified: 2024-01-29
Priority: 2
View other active issues in [range.utility.conv.to].
View all other issues in [range.utility.conv.to].
View all issues with C++23 status.
Discussion:
The intention of ranges::to is to construct a non-view object, which is reflected in its constraint that object type C should not model a view.
The specification allows C to be a const-qualified type which does not satisfy view such as const string_view, making ranges::to return a dangling view. We should ban such cases.
[2023-02-01; Reflector poll]
Set priority to 2 after reflector poll. Just require C to be a cv-unqualified object type.
Previous resolution [SUPERSEDED]:
This wording is relative to N4917.
- Modify 25.2 [ranges.syn] as indicated:
#include // see 17.12.1 [compare.syn]
#include // see 17.11.2 [initializer.list.syn]
#include // see 24.2 [iterator.synopsis]namespace std::ranges {
[…]
// 25.5.7 [range.utility.conv], range conversions
template<class C, input_range R, class... Args> requires (!view<remove_cv_t>)
constexpr C to(R&& r, Args&&... args); // freestanding
template<template<class...> class C, input_range R, class... Args>
constexpr auto to(R&& r, Args&&... args); // freestanding
template<class C, class... Args> requires (!view<remove_cv_t>)
constexpr auto to(Args&&... args); // freestanding
template<template<class...> class C, class... Args>
constexpr auto to(Args&&... args); // freestanding
[…]
}- Modify 25.5.7.2 [range.utility.conv.to] as indicated:
template<class C, input_range R, class... Args> requires (!view<remove_cv_t>)
constexpr C to(R&& r, Args&&... args);-1- Returns: An object of type
Cconstructed from the elements ofrin the following manner:[…]
- Modify 25.5.7.3 [range.utility.conv.adaptors] as indicated:
template<class C, class... Args> requires (!view<remove_cv_t>)
constexpr auto to(Args&&... args);
template<template<class...> class C, class... Args>
constexpr auto to(Args&&... args);-1- Returns: A range adaptor closure object (25.7.2 [range.adaptor.object])
fthat is a perfect forwarding call wrapper (22.10.4 [func.require]) with the following properties:[…]
[2023-02-02; Jonathan provides improved wording]
[Issaquah 2023-02-08; LWG]
Unanimous consent to move to Immediate. This also resolves LWG 3787(i).
[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP.]
Proposed resolution:
This wording is relative to N4928.
- Modify 25.5.7.2 [range.utility.conv.to] as indicated:
template<class C, input_range R, class... Args> requires (!view)
constexpr C to(R&& r, Args&&... args);-?- Mandates:
Cis a cv-unqualified class type.-1- Returns: An object of type
Cconstructed from the elements ofrin the following manner:[…]
- Modify 25.5.7.3 [range.utility.conv.adaptors] as indicated:
template<class C, class... Args> requires (!view)
constexpr auto to(Args&&... args);
template<template<class...> class C, class... Args>
constexpr auto to(Args&&... args);-?- Mandates: For the first overload,
Cis a cv-unqualified class type.-1- Returns: A range adaptor closure object (25.7.2 [range.adaptor.object])
fthat is a perfect forwarding call wrapper (22.10.4 [func.require]) with the following properties:[…]