Title
[fund.ts.v2] to_array should take rvalue reference as well
Status
resolved
Section
[func.wrap.func.con]
Submitter
Zhihao Yuan

Created on 2016-11-07.00:00:00 last changed 48 months ago

Messages

Date: 2020-05-10.11:23:30
Resolved by

Rationale:

P0325R4 and P2081R1.
Date: 2020-05-15.00:00:00

[ 2020-05-10; Reflector discussions ]

Resolved by adoption of P0325R4 and P2081R1.

Date: 2017-06-02.00:00:00

[ 2017-06-02 Issues Telecon ]

Leave status as LEWG; priority 3

Previous resolution [SUPERSEDED]:

This wording is relative to N4600.

  1. Add the following signature to [header.array.synop]:

    // 9.2.2, Array creation functions
    template <class D = void, class... Types>
      constexpr array<VT, sizeof...(Types)> make_array(Types&&... t);
    template <class T, size_t N>
      constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
    template <class T, size_t N>
      constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
    
  2. Modify [container.array.creation] as follows:

    template <class T, size_t N>
      constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
    template <class T, size_t N>
      constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
    

    -6- Returns: For all i, 0 ≤ i < N, aAn array<remove_cv_t<T>, N> such that each element is copy-initialized with the corresponding element of ainitialized with { a[i]... } for the first form, or { std::move(a[i])... } for the second form..

Date: 2017-06-05.15:41:21

[ 2017-02 in Kona, LEWG responds ]

Would like a small paper; see examples before and after. How does this affect overload resolution?

Date: 2017-02-02.00:41:18

[ Issues Telecon 16-Dec-2016 ]

Status to LEWG

Date: 2017-05-13.10:02:14

Addresses: fund.ts.v2

C++ doesn't have a prvalue expression of array type, but rvalue arrays can still come from different kinds of sources:

  1. C99 compound literals (int[]) {2, 4},

  2. std::move(arr),

  3. Deduction to_array<int const>({ 2, 4 }).

    See also CWG 1591: Deducing array bound and element type from initializer list.

For 3), users are "abusing" to_array to get access to uniform initialization to benefit from initializing elements through braced-init-list and/or better narrowing conversion support.

We should just add rvalue reference support to to_array.

History
Date User Action Args
2020-05-10 11:23:30adminsetmessages: + msg11284
2020-05-10 11:23:30adminsetstatus: lewg -> resolved
2017-06-05 15:41:21adminsetmessages: + msg9228
2017-06-05 15:41:21adminsetmessages: + msg9227
2016-12-16 20:56:38adminsetmessages: + msg8745
2016-12-16 20:56:38adminsetstatus: new -> lewg
2016-11-13 14:10:49adminsetmessages: + msg8633
2016-11-07 00:00:00admincreate