Use move construction in swap implementation (#103)

* Use correct type alias in swap helper function

This was not an issue since both t_is_nothrow_move_constructible and
e_is_nothrow_move_constructible are type aliases for std::true_type.

* Use move instead of copy in swap implementation
This commit is contained in:
Simon Truscott
2022-11-25 00:17:42 +11:00
committed by GitHub
parent f88d817e06
commit cd8c7920b3

View File

@@ -1837,12 +1837,12 @@ private:
void swap_where_only_one_has_value_and_t_is_not_void(
expected &rhs, move_constructing_t_can_throw,
t_is_nothrow_move_constructible) {
e_is_nothrow_move_constructible) {
auto temp = std::move(rhs.err());
rhs.err().~unexpected_type();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
::new (rhs.valptr()) T(val());
::new (rhs.valptr()) T(std::move(val()));
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
@@ -1851,7 +1851,7 @@ private:
throw;
}
#else
::new (rhs.valptr()) T(val());
::new (rhs.valptr()) T(std::move(val()));
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);