swappable
traits for optional
sSection: 22.5.3.5 [optional.swap], 22.5.9 [optional.specalg] Status: C++17 Submitter: Agustín K-ballo Bergé Opened: 2016-07-19 Last modified: 2017-07-30
Priority: 0
View all issues with C++17 status.
Discussion:
optional
didn't benefit from the wording modifications by P0185 "Adding [nothrow_
]swappable
traits"; as such, it suffers from LWG 2456, and does not play nice with swappable traits.
[2016-07 Chicago]
Monday: P0 - tentatively ready
Proposed resolution:
This wording is relative to N4606.
Modify [optional.object.swap] as indicated:
void swap(optional<T>& rhs) noexcept(see below);[…]
-4- Remarks: The expression insidenoexcept
is equivalent to:is_nothrow_move_constructible_v<T> && is_nothrow_swappable_v<T>noexcept(swap(declval<T&>(), declval<T&>()))
Modify 22.5.9 [optional.specalg] as indicated:
template <class T> void swap(optional<T>& x, optional<T>& y) noexcept(noexcept(x.swap(y)));-1- Effects: Calls
-?- Remarks: This function shall not participate in overload resolution unlessx.swap(y)
.is_move_constructible_v<T>
istrue
andis_swappable_v<T>
istrue
.