Title
Excessive unwrapping in std::ref/cref
Status
new
Section
[refwrap.helpers]
Submitter
Agustín K-ballo Bergé

Created on 2018-07-10.00:00:00, last changed 2018-08-22.12:55:05.

Messages

Date: 2018-08-22.12:55:05

Proposed resolution:

This wording is relative to N4762.

  1. Change [refwrap.helpers] as indicated:

    template<class T> reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;
    

    -2- Returns: ref(t.get())t.

    […]
    template<class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
    

    -4- Returns: cref(t.get())t.

Date: 2018-08-20.00:00:00

[ 2018-08-20 Priority set to 3 after reflector discussion ]

Date: 2018-07-10.00:00:00

The overloads of std::ref/cref that take a reference_wrapper as argument are defined as calling std::ref/cref recursively, whereas the return type is defined as unwrapping just one level. Calling these functions with arguments of multiple level of wrapping leads to ill-formed programs:

int i = 0;
std::reference_wrapper<int> ri(i);
std::reference_wrapper<std::reference_wrapper<int>> rri(ri);
std::ref(rri); // error within 'std::ref'

[Note: these overloads were added by issue resolution 10.29 for TR1, which can be found at N1688, at Redmond 2004]

History
Date User Action Args
2018-08-22 12:55:05adminsetmessages: + msg10061
2018-07-30 20:47:23adminsetmessages: + msg10014
2018-07-10 00:00:00admincreate