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 and y must both be non-null and properly aligned for T.
  • The memory region at x and including count elements must not overlap the region at y including count elements.
  • The objects at x and y must not have an overlapping object in their tail padding. If x and y are arrays, or were heap allocated, then this will always be satisfied.