summaryrefslogtreecommitdiff
path: root/lib/nes/common/list.hh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nes/common/list.hh')
-rw-r--r--lib/nes/common/list.hh24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/nes/common/list.hh b/lib/nes/common/list.hh
index b1fddf0..46f7027 100644
--- a/lib/nes/common/list.hh
+++ b/lib/nes/common/list.hh
@@ -1,5 +1,7 @@
#pragma once
+#include "nes/common/debug.hh"
+
namespace nes
{
/// An intrusive doubly-linked list.
@@ -39,15 +41,23 @@ namespace nes
auto operator==(iterator const& other) -> bool { return current_ == other.current_; }
auto operator!=(iterator const& other) -> bool { return current_ != other.current_; }
- auto operator*() const -> T* { return current_; }
+ auto operator*() const -> T&
+ {
+ NES_ASSERT(current_ != nullptr && "invalid iterator");
+ return *current_;
+ }
+
+ auto operator->() const -> T*
+ {
+ NES_ASSERT(current_ != nullptr && "invalid iterator");
+ return current_;
+ }
auto operator++() -> iterator&
{
- if (current_)
- {
- node& current_node = *current_;
- current_ = current_node.next_;
- }
+ NES_ASSERT(current_ != nullptr && "invalid iterator");
+ node& current_node = *current_;
+ current_ = current_node.next_;
return *this;
}
@@ -126,7 +136,7 @@ namespace nes
/// Remove an item from the list by its iterator.
auto remove(iterator it) -> bool
{
- if (it != end()) { return remove(**it); }
+ if (it != end()) { return remove(*it); }
return false;
}
};