3173. Enable CTAD for ref-view

Section: 25.7.6.2 [range.ref.view] Status: C++20 Submitter: Casey Carter Opened: 2018-12-09 Last modified: 2021-06-06

Priority: 0

View all issues with C++20 status.

Discussion:

In the specification of view::all in 25.7.6 [range.all], paragraph 2.2 states that view::all(E) is sometimes expression-equivalent to "ref-view{E} if that expression is well-formed". Unfortunately, the expression ref-view{E} is never well-formed: ref-view's only non-default constructor is a perfect-forwarding-ish constructor template that accepts only arguments that convert to lvalues of the ref-view's template argument type, and either do not convert to rvalues or have a better lvalue conversion (similar to the reference_wrapper converting constructor (22.10.6.2 [refwrap.const]) after issue 2993).

Presumably this breakage was not intentional, and we should add a deduction guide to enable class template argument deduction to function as intended by paragraph 2.2.

[2018-12-16 Status to Tentatively Ready after six positive votes on the reflector.]

Proposed resolution:

This wording is relative to N4791.

  1. Modify the ref-view class synopsis in [ranges.view.ref] as follows:

    namespace std::ranges {
      template<Range R>
        requires is_object_v<R>
      class ref-view : public view_interface<ref-view<R>> {
        […]
      };
    
      template<class R>
        ref_view(R&) -> ref_view<R>;
    }