Commit 8d679e7e authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

util/IntrusiveList: add IntrusiveList::swap()

parent 2b30ac23
......@@ -167,6 +167,29 @@ public:
IntrusiveList &operator=(IntrusiveList &&) = delete;
friend void swap(IntrusiveList &a, IntrusiveList &b) noexcept {
using std::swap;
if (a.empty()) {
if (b.empty())
return;
a.head = b.head;
a.head.next->prev = &a.head;
a.head.prev->next = &a.head;
b.head = {&b.head, &b.head};
} else {
swap(a.head, b.head);
a.head.next->prev = &a.head;
a.head.prev->next = &a.head;
b.head.next->prev = &b.head;
b.head.prev->next = &b.head;
}
}
constexpr bool empty() const noexcept {
return head.next == &head;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment