Title
ranges::to's template parameter C should not be a reference type
Status
resolved
Section
[range.utility.conv.to][range.utility.conv.adaptors]
Submitter
Hewill Kang

Created on 2022-09-25.00:00:00 last changed 21 months ago

Messages

Date: 2023-03-22.12:28:35

Proposed resolution:

This wording is relative to N4917.

  1. Modify [ranges.syn], header <ranges> synopsis, as indicated:

    #include <compare>              // see [compare.syn]
    #include <initializer_list>     // see [initializer.list.syn]
    #include <iterator>             // see [iterator.synopsis]
    
    namespace std::ranges {
      […]
      // [range.utility.conv], range conversions
      template<class C, input_range R, class... Args> requires is_object_v<C> && (!view<C>)
        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 is_object_v<C> && (!view<C>)
        constexpr auto to(Args&&... args);                                              // freestanding
      template<template<class...> class C, class... Args>
        constexpr auto to(Args&&... args);                                              // freestanding
      […]
    }
    
  2. Modify [range.utility.conv.to] as indicated:

    template<class C, input_range R, class... Args> requires is_object_v<C> && (!view<C>)
    constexpr C to(R&& r, Args&&... args);
    

    -1- Returns: An object of type C constructed from the elements of r in the following manner:

    […]
  3. Modify [range.utility.conv.adaptors] as indicated:

    template<class C, class... Args> requires is_object_v<C> && (!view<C>)
      constexpr auto to(Args&&... args);
    template<template<class...> class C, class... Args>
      constexpr auto to(Args&&... args);
    

    -1- Returns: A range adaptor closure object ([range.adaptor.object]) f that is a perfect forwarding call wrapper ([func.require]) with the following properties:

    […]
Date: 2023-03-22.00:00:00

[ 2023-03-22 LWG 3847 was approved in Issaquah. Status changed: New → Resolved. ]

Date: 2023-02-08.23:20:46

[ Issaquah 2023-02-08; LWG ]

This would be resolved by LWG 3847.

Date: 2022-09-15.00:00:00

[ 2022-09-28; Reflector poll ]

Set priority to 3 after reflector poll. Some suggestions that it should be Mandates: not Constraints:, but no consensus.

Date: 2022-09-25.00:00:00

It doesn't make sense for the template parameter C of ranges::to be a reference, which allows us to write something like ranges::to<vector<int>&&>(std::move(v)) or ranges::to<const vector<int>&&>(v), we should forbid this.

The proposed resolution constrains the template parameter C to be object type to conform to its description: "The range conversion functions construct an object (usually a container) from a range".

History
Date User Action Args
2023-03-22 12:28:35adminsetmessages: + msg13462
2023-03-22 12:28:35adminsetstatus: new -> resolved
2023-02-08 23:19:55adminsetmessages: + msg13296
2022-09-28 20:08:32adminsetmessages: + msg12831
2022-09-25 17:08:29adminsetmessages: + msg12817
2022-09-25 00:00:00admincreate