Title
variant's copies must be deleted instead of disabled via SFINAE
Status
c++20
Section
[variant.ctor]
Submitter
Casey Carter

Created on 2017-10-10.00:00:00 last changed 45 months ago

Messages

Date: 2017-10-15.14:35:29

Proposed resolution:

This wording is relative to N4687.

  1. Change [variant.ctor] as indicated:

    variant(const variant& w);
    

    -6- Effects: If w holds a value, initializes the variant to hold the same alternative as w and direct-initializes the contained value with get<j>(w), where j is w.index(). Otherwise, initializes the variant to not hold a value.

    -7- Throws: Any exception thrown by direct-initializing any Ti for all i.

    -8- Remarks: This function shall not participate in overload resolutionconstructor shall be defined as deleted unless is_copy_constructible_v<Ti> is true for all i.

  2. Change [variant.assign] as indicated:

    variant& operator=(const variant& rhs);
    

    […]

    -4- Postconditions: index() == rhs.index().

    -5- Remarks: This function shall not participate in overload resolutionoperator shall be defined as deleted unless is_copy_constructible_v<Ti> && is_copy_assignable_v<Ti> is true for all i.

Date: 2017-10-11.00:00:00

[ 2017-10-11 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

Date: 2017-10-10.00:00:00

The specification of variant's copy constructor and copy assignment operator require that those functions do not participate in overload resolution unless certain conditions are satisfied. There is no mechanism in C++ that makes it possible to prevent a copy constructor or copy assignment operator from participating in overload resolution. These functions should instead be specified to be defined as deleted unless the requisite conditions hold, as we did for the copy constructor and copy assignment operator of optional in LWG 2756.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2017-11-13 19:01:36adminsetstatus: voting -> wp
2017-10-17 18:35:42adminsetstatus: ready -> voting
2017-10-15 14:35:29adminsetmessages: + msg9476
2017-10-15 14:35:29adminsetstatus: new -> ready
2017-10-10 16:09:44adminsetmessages: + msg9473
2017-10-10 00:00:00admincreate