On Mon, 30 May 2022 at 12:07, Arthur O'Dwyer <arthur.j.odwyer@gmail.com> wrote:
On Mon, May 30, 2022 at 1:56 PM Edward Catmur <ecatmur@googlemail.com> wrote:
[...]
template<class T> requires std::is_noexcept_relocatable_v<T>
void swap(T& lhs, T& rhs) {
    T temp = relocate_at(&lhs);
    new (&lhs) T(relocate_at(&rhs));
    new (&rhs) T(relocate_at(&temp));
}

(relocate_at is the magic library function that (destroys and) relocates its argument into a returned prvalue.)

Terminology nit: `relocate_at` takes a pointer parameter `dest`, just like `construct_at` and `destroy_at`.
`relocate` with no suffix is the magic library function that relocates into a returned prvalue.

Ah, yeah, thanks. And that last relocate is incorrect; it should use the relocation operator keyword, since temp should not be destroyed at the end of scope:

template<class T> requires is_noexcept_relocatable_v<T>
void swap(T& lhs, T& rhs) {
    T temp = relocate(&lhs);
    relocate_at(&rhs, &lhs);
    new (&rhs) T(reloc temp);
}