Title
Missing SFINAE on std::pair::operator=
Status
c++17
Section
[pairs.pair][tuple.assign]
Submitter
Richard Smith

Created on 2016-06-07.00:00:00 last changed 89 months ago

Messages

Date: 2016-08-05.03:58:49

Proposed resolution:

This wording is relative to N4606.

  1. Change [pairs.pair] as indicated:

    pair& operator=(const pair& p);
    

    -15- RequiresRemarks: This operator shall be defined as deleted unless is_copy_assignable_v<first_type> is true and is_copy_assignable_v<second_type> is true.

    […]

    template<class U, class V> pair& operator=(const pair<U, V>& p);
    

    -18- RequiresRemarks: This operator shall not participate in overload resolution unless is_assignable_v<first_type&, const U&> is true and is_assignable_v<second_type&, const V&> is true.

    […]

    pair& operator=(pair&& p) noexcept(see below);
    

    -21- Remarks: The expression inside noexcept is equivalent to:

    is_nothrow_move_assignable_v<T1> && is_nothrow_move_assignable_v<T2>
    

    -22- RequiresRemarks: This operator shall be defined as deleted unless is_move_assignable_v<first_type> is true and is_move_assignable_v<second_type> is true.

    […]

    template<class U, class V> pair& operator=(pair<U, V>&& p);
    

    -25- RequiresRemarks: This operator shall not participate in overload resolution unless is_assignable_v<first_type&, U&&> is true and is_assignable_v<second_type&, V&&> is true.

  2. Change [tuple.assign] as indicated:

    tuple& operator=(const tuple& u);
    

    -2- RequiresRemarks: This operator shall be defined as deleted unless is_copy_assignable_v<Ti> is true for all i.

    […]

    tuple& operator=(tuple&& u) noexcept(see below);
    

    -5- Remark: The expression inside noexcept is equivalent to the logical AND of the following expressions:

    is_nothrow_move_assignable_v<Ti>
    

    where Ti is the ith type in Types.

    -6- RequiresRemarks: This operator shall be defined as deleted unless is_move_assignable_v<Ti> is true for all i.

    […]

    template <class... UTypes>
      tuple& operator=(const tuple<UTypes...>& u);
    

    -9- RequiresRemarks: This operator shall not participate in overload resolution unless sizeof...(Types) == sizeof...(UTypes) and is_assignable_v<Ti&, const Ui&> is true for all i.

    […]

    template <class... UTypes>
      tuple& operator=(tuple<UTypes...>&& u);
    

    -12- RequiresRemarks: This operator shall not participate in overload resolution unless is_assignable_v<Ti&, Ui&&> == true for all i. and sizeof...(Types) == sizeof...(UTypes).

    […]

    template <class U1, class U2> tuple& operator=(const pair<U1, U2>& u);
    

    -15- RequiresRemarks: This operator shall not participate in overload resolution unless sizeof...(Types) == 2. and is_assignable_v<T0&, const U1&> is true for the first type T0 in Types and is_assignable_v<T1&, const U2&> is true for the second type T1 in Types.

    […]

    template <class U1, class U2> tuple& operator=(pair<U1, U2>&& u);
    

    -18- RequiresRemarks: This operator shall not participate in overload resolution unless sizeof...(Types) == 2. and is_assignable_v<T0&, U1&&> is true for the first type T0 in Types and is_assignable_v<T1&, U2&&> is true for the second type T1 in Types.

Date: 2016-08-05.03:58:49

[ 2016-08 - Chicago ]

Thurs PM: Moved to Tentatively Ready

Lots of discussion, but no one had a better idea.

Date: 2016-08-03.00:00:00

[ 2016-08-03 Chicago LWG ]

Inspired by Eric Fiselier and Ville, Walter and Nevin provide initial Proposed Resolution.

Date: 2016-06-07.00:00:00

std::is_copy_assignable<std::pair<int, std::unique_ptr<int>>>::value is true, and should be false. We're missing a "shall not participate in overload resolution unless" for pair's operator=, and likewise for tuple.

History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-11-14 03:59:28adminsetstatus: pending -> wp
2016-11-14 03:55:22adminsetstatus: ready -> pending
2016-08-05 03:58:49adminsetmessages: + msg8422
2016-08-05 03:58:49adminsetstatus: new -> ready
2016-08-04 17:57:31adminsetmessages: + msg8394
2016-08-04 17:57:31adminsetmessages: + msg8393
2016-06-07 00:00:00admincreate