Function Subspace :: sus :: ptr :: swap_nonoverlapping
template <class T>
auto swap_nonoverlapping(UnsafeFnMarker, T* x, T* y, sus::usize count) -> void
requires
sus::mem::Move<T>
!std::is_const_v<T>
Swaps the object array at x
with the object array at y
, where both
arrays have a length of count
.
If T
is trivially relocatable (sus::mem::TriviallyRelocatable<T>
is true),
then the swap may be done by memcpy() or equivalent to be more efficient.
Safety
To avoid Undefined Behaviour, the following must be met:
- The pointers
x
andy
must both be non-null and properly aligned forT
. - The memory region at
x
and includingcount
elements must not overlap the region aty
includingcount
elements. - The objects at
x
andy
must not have an overlapping object in their tail padding. Ifx
andy
are arrays, or were heap allocated, then this will always be satisfied.