std::swap noexcept workaround is inaccurate
martinmoene opened this issue · 1 comments
martinmoene commented
martinmoene commented
This now is solved by using std(17)::is_nothrow_swappable<>
as written in p0323r7.
A solution to this problem involving ADL can be seen in Vicente J. Botet Escriba's expected.
See also this SO question.
namespace adl {
using std::swap;
template <class T, class U>
void swap_impl( T& x, U& y ) noexcept( noexcept( swap(x, y) ) )
{
swap(x, y);
}
}
// expected<T,E>
// expected<void,E>
// member operator=()
// member emplace()
// member swap()
template <class T, class E>
void expected<T,E>::swap( expected& rhs ) noexcept
(
is_nothrow_move_constructible<T>::value
&& is_nothrow_move_constructible<E>::value
&& noexcept( adl::swap_impl( declval<T&>(), declval<T&>() ) )
&& noexcept( adl::swap_impl( declval<E&>(), declval<E&>() ) )
)
{
...
}