Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions include/stdx/detail/list_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ concept base_double_linkable = base_single_linkable<T> and requires(T node) {
} // namespace detail

template <typename T>
concept single_linkable = not complete<T> or requires(T *node) {
concept single_linkable = requires(T *node) {
requires detail::base_single_linkable<
std::remove_cvref_t<decltype(node->next)>>;
};

template <typename T>
concept double_linkable = not complete<T> or requires(T *node) {
concept double_linkable = requires(T *node) {
requires detail::base_double_linkable<
std::remove_cvref_t<decltype(node->next)>>;
requires detail::base_double_linkable<
Expand All @@ -46,6 +46,7 @@ constexpr auto
namespace node_policy {
template <typename Node> class checked {
constexpr static auto valid_for_push(Node *node) -> bool {
static_assert(single_linkable<Node>);
if constexpr (detail::detect::has_prev_pointer<Node>) {
return node->prev == nullptr and node->next == nullptr;
} else {
Expand Down Expand Up @@ -79,13 +80,15 @@ template <typename Node> class checked {
}

constexpr static auto on_pop(Node *node) {
static_assert(single_linkable<Node>);
if constexpr (detail::detect::has_prev_pointer<Node>) {
node->prev = nullptr;
}
node->next = nullptr;
}

constexpr static auto on_clear(Node *head) {
static_assert(single_linkable<Node>);
while (head != nullptr) {
if constexpr (detail::detect::has_prev_pointer<Node>) {
head->prev = nullptr;
Expand Down
5 changes: 4 additions & 1 deletion include/stdx/intrusive_forward_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace stdx {
inline namespace v1 {
template <single_linkable NodeType,
template <typename NodeType,
template <typename> typename P = node_policy::checked>
class intrusive_forward_list {
friend P<NodeType>;
Expand Down Expand Up @@ -58,6 +58,7 @@ class intrusive_forward_list {
pointer tail{};

constexpr auto unchecked_push_front(pointer n) -> void {
static_assert(single_linkable<value_type>);
n->next = head;
head = n;
if (tail == nullptr) {
Expand All @@ -66,6 +67,7 @@ class intrusive_forward_list {
}

constexpr auto unchecked_push_back(pointer n) -> void {
static_assert(single_linkable<value_type>);
if (tail != nullptr) {
tail->next = n;
}
Expand Down Expand Up @@ -99,6 +101,7 @@ class intrusive_forward_list {
}

constexpr auto pop_front() -> pointer {
static_assert(single_linkable<value_type>);
pointer poppedNode = head;
head = head->next;

Expand Down
8 changes: 7 additions & 1 deletion include/stdx/intrusive_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace stdx {
inline namespace v1 {
template <double_linkable NodeType,
template <typename NodeType,
template <typename> typename P = node_policy::checked>
class intrusive_list {
friend P<NodeType>;
Expand Down Expand Up @@ -58,6 +58,7 @@ class intrusive_list {
pointer tail{};

constexpr auto unchecked_push_front(pointer n) -> void {
static_assert(double_linkable<value_type>);
if (head != nullptr) {
head->prev = n;
}
Expand All @@ -70,6 +71,7 @@ class intrusive_list {
}

constexpr auto unchecked_push_back(pointer n) -> void {
static_assert(double_linkable<value_type>);
if (tail != nullptr) {
tail->next = n;
}
Expand All @@ -82,6 +84,7 @@ class intrusive_list {
}

constexpr auto unchecked_insert(iterator it, pointer n) -> void {
static_assert(double_linkable<value_type>);
if (it != end()) {
auto p = it.operator->();
n->next = p;
Expand Down Expand Up @@ -128,6 +131,7 @@ class intrusive_list {
}

constexpr auto pop_front() -> pointer {
static_assert(double_linkable<value_type>);
pointer poppedNode = head;
head = head->next;

Expand All @@ -142,6 +146,7 @@ class intrusive_list {
}

constexpr auto pop_back() -> pointer {
static_assert(double_linkable<value_type>);
pointer poppedNode = tail;
tail = tail->prev;

Expand All @@ -166,6 +171,7 @@ class intrusive_list {
}

constexpr auto remove(pointer n) -> void {
static_assert(double_linkable<value_type>);
pointer nextNode = n->next;
pointer prevNode = n->prev;

Expand Down