Function Subspace :: sus :: mem :: replace

template <class T, class U>
auto replace(T& dest, const U& src) -> T
requires
std::convertible_to<U, T>
!std::is_array_v<T>
sus::mem::Move<T>
!std::is_const_v<T>
!std::same_as<T, U> || ::sus::mem::Copy<T>
template <class T, class U>
auto replace(T& dest, U&& src) -> T
requires
std::convertible_to<U, T>
!std::is_array_v<T>
sus::mem::Move<T>
!std::is_const_v<T>
sus::mem::IsMoveRef<decltype(src)>

Replace the dest with src, and return the old value in dest.

This is equivalent to:

T old = sus::move(dest);
dest = sus::forward<T>(src);
return old;

This operation is known as std::exchange() in the stdlib.