Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify optional::swap conditions #5065

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions stl/inc/optional
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,12 @@ public:

_CONSTEXPR20 void swap(optional& _Right)
noexcept(is_nothrow_move_constructible_v<_Ty> && is_nothrow_swappable_v<_Ty>) {
static_assert(is_move_constructible_v<_Ty>,
"optional<T>::swap requires T to be move constructible (N4950 [optional.swap]/1).");
static_assert(!is_move_constructible_v<_Ty> || is_swappable_v<_Ty>,
"optional<T>::swap requires T to be swappable (N4950 [optional.swap]/2).");
if constexpr (is_move_constructible_v<_Ty>) {
static_assert(
is_swappable_v<_Ty>, "optional<T>::swap requires T to be swappable (N4993 [optional.swap]/2).");
} else {
static_assert(false, "optional<T>::swap requires T to be move constructible (N4993 [optional.swap]/1).");
}
using _STD swap;
if constexpr (_Is_trivially_swappable_v<_Ty>) {
using _TrivialBaseTy = _Optional_destruct_base<_Ty>;
Expand Down