Recti 1.2.4
Loading...
Searching...
No Matches
dllink.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cassert>
8#include <utility> // for std::move()
9
10// Forward declaration for begin() end()
11class RDllist;
12class RDllIterator;
13
27#pragma pack(push, 1)
28template <typename T> class Dllink {
29 public:
30 Dllink* next{this};
31 Dllink* prev{this};
32 T data{};
39 constexpr explicit Dllink(T dat) noexcept : data{std::move(dat)} {
40 static_assert(sizeof(Dllink) <= 24, "keep this class small");
41 }
42
47 constexpr Dllink() = default;
48 ~Dllink() = default;
49 Dllink(const Dllink&) = delete; // don't copy
50 auto operator=(const Dllink&) -> Dllink& = delete; // don't assign
51 constexpr Dllink(Dllink&&) noexcept = default;
52 constexpr auto operator=(Dllink&&) noexcept -> Dllink& = delete; // don't assign
53
58 constexpr auto lock() noexcept -> void { this->next = this; }
59
65 constexpr auto is_locked() const noexcept -> bool { return this->next == this; }
66
71 constexpr auto detach() noexcept -> void {
72 assert(!this->is_locked());
73 const auto n = this->next;
74 const auto p = this->prev;
75 p->next = n;
76 n->prev = p;
77 }
78
79 private:
85 constexpr auto attach(Dllink& node) noexcept -> void {
86 node.next = this->next;
87 this->next->prev = &node;
88 this->next = &node;
89 node.prev = this;
90 }
91};
92#pragma pack(pop)
Iterator for RDllist circular doubly-linked list.
Definition rdllist.hpp:19
Circular doubly-linked list implementation.
Definition rdllist.hpp:55