LinkedList: Return Option instead of ENONE if no value

This commit is contained in:
apio 2022-12-08 16:09:04 +01:00
parent 406af68a54
commit b6173e2b67
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 9 additions and 9 deletions

View File

@ -102,7 +102,7 @@ namespace Scheduler
if (old->is_idle()) if (old->is_idle())
{ {
auto maybe_last = g_threads.last(); auto maybe_last = g_threads.last();
if (maybe_last.has_error()) // No threads!! if (!maybe_last.has_value()) // No threads!!
return &g_idle; return &g_idle;
g_current = old = maybe_last.value(); g_current = old = maybe_last.value();
} }
@ -111,7 +111,7 @@ namespace Scheduler
do { do {
auto maybe_next = g_threads.next(g_current); auto maybe_next = g_threads.next(g_current);
if (maybe_next.has_error()) g_current = g_threads.expect_first(); if (!maybe_next.has_value()) g_current = g_threads.expect_first();
else else
g_current = maybe_next.value(); g_current = maybe_next.value();

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#include <luna/Result.h> #include <luna/Option.h>
template <typename T> inline Result<T*> nonnull_or_error(T* ptr) template <typename T> inline Option<T*> nonnull_or_error(T* ptr)
{ {
if (ptr == nullptr) return err(ENONE); if (ptr == nullptr) return {};
else else
return ptr; return ptr;
} }
@ -101,7 +101,7 @@ template <typename T> class DoublyLinkedList
return ptr; return ptr;
} }
Result<T*> first() Option<T*> first()
{ {
return nonnull_or_error((T*)m_start_node); return nonnull_or_error((T*)m_start_node);
} }
@ -111,7 +111,7 @@ template <typename T> class DoublyLinkedList
return first().value(); return first().value();
} }
Result<T*> last() Option<T*> last()
{ {
return nonnull_or_error((T*)m_end_node); return nonnull_or_error((T*)m_end_node);
} }
@ -121,12 +121,12 @@ template <typename T> class DoublyLinkedList
return last().value(); return last().value();
} }
Result<T*> next(T* item) Option<T*> next(T* item)
{ {
return nonnull_or_error((T*)extract_node(item)->get_next()); return nonnull_or_error((T*)extract_node(item)->get_next());
} }
Result<T*> previous(T* item) Option<T*> previous(T* item)
{ {
return nonnull_or_error((T*)extract_node(item)->get_last()); return nonnull_or_error((T*)extract_node(item)->get_last());
} }