summaryrefslogtreecommitdiff
path: root/asl/containers
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-20 23:47:02 +0100
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2025-02-20 23:47:02 +0100
commitaa73023bee1aebc745188e54039d3bf567be97e3 (patch)
treee4d3385a7e9eedfff7b36a8237771441668ca7cc /asl/containers
parent409ef997e2ff99b2bbea89ea61d10fc8e26dac96 (diff)
Use intrusive list in logging, and add defer
Diffstat (limited to 'asl/containers')
-rw-r--r--asl/containers/intrusive_list.hpp7
-rw-r--r--asl/containers/intrusive_list_tests.cpp60
2 files changed, 36 insertions, 31 deletions
diff --git a/asl/containers/intrusive_list.hpp b/asl/containers/intrusive_list.hpp
index f061740..dcf0508 100644
--- a/asl/containers/intrusive_list.hpp
+++ b/asl/containers/intrusive_list.hpp
@@ -34,6 +34,11 @@ class IntrusiveList
public:
constexpr IntrusiveList() = default;
+ explicit IntrusiveList(T* head)
+ {
+ push_front(head);
+ }
+
ASL_DELETE_COPY(IntrusiveList)
ASL_DEFAULT_MOVE(IntrusiveList)
~IntrusiveList() = default;
@@ -121,7 +126,7 @@ public:
{
if (!is_empty())
{
- T* node = m_head->prev;
+ T* node = m_head->m_prev;
detach(node);
return node;
}
diff --git a/asl/containers/intrusive_list_tests.cpp b/asl/containers/intrusive_list_tests.cpp
index 242aaf6..ceb54a6 100644
--- a/asl/containers/intrusive_list_tests.cpp
+++ b/asl/containers/intrusive_list_tests.cpp
@@ -194,33 +194,33 @@ ASL_TEST(pop_front)
ASL_TEST_ASSERT(list.is_empty());
}
-// ASL_TEST(pop_back)
-// {
-// IntNode one{1};
-// IntNode two{2};
-// IntNode three{3};
-// asl::IntrusiveList<IntNode> list;
-
-// list.push_back(&one);
-// list.push_back(&two);
-// list.push_back(&three);
-
-// IntNode* n = list.pop_back();
-// ASL_TEST_ASSERT(n != nullptr);
-// ASL_TEST_ASSERT(!list.is_empty());
-// ASL_TEST_EXPECT(n->value == 3);
-
-// n = list.pop_back();
-// ASL_TEST_ASSERT(n != nullptr);
-// ASL_TEST_ASSERT(!list.is_empty());
-// ASL_TEST_EXPECT(n->value == 2);
-
-// n = list.pop_back();
-// ASL_TEST_ASSERT(n != nullptr);
-// ASL_TEST_ASSERT(list.is_empty());
-// ASL_TEST_EXPECT(n->value == 1);
-
-// n = list.pop_back();
-// ASL_TEST_ASSERT(n == nullptr);
-// ASL_TEST_ASSERT(list.is_empty());
-// }
+ASL_TEST(pop_back)
+{
+ IntNode one{1};
+ IntNode two{2};
+ IntNode three{3};
+ asl::IntrusiveList<IntNode> list;
+
+ list.push_back(&one);
+ list.push_back(&two);
+ list.push_back(&three);
+
+ IntNode* n = list.pop_back();
+ ASL_TEST_ASSERT(n != nullptr);
+ ASL_TEST_ASSERT(!list.is_empty());
+ ASL_TEST_EXPECT(n->value == 3);
+
+ n = list.pop_back();
+ ASL_TEST_ASSERT(n != nullptr);
+ ASL_TEST_ASSERT(!list.is_empty());
+ ASL_TEST_EXPECT(n->value == 2);
+
+ n = list.pop_back();
+ ASL_TEST_ASSERT(n != nullptr);
+ ASL_TEST_ASSERT(list.is_empty());
+ ASL_TEST_EXPECT(n->value == 1);
+
+ n = list.pop_back();
+ ASL_TEST_ASSERT(n == nullptr);
+ ASL_TEST_ASSERT(list.is_empty());
+}