Add an Option type and get rid of ENONE #19
@ -102,7 +102,7 @@ namespace Scheduler
|
||||
if (old->is_idle())
|
||||
{
|
||||
auto maybe_last = g_threads.last();
|
||||
if (maybe_last.has_error()) // No threads!!
|
||||
if (!maybe_last.has_value()) // No threads!!
|
||||
return &g_idle;
|
||||
g_current = old = maybe_last.value();
|
||||
}
|
||||
@ -111,7 +111,7 @@ namespace Scheduler
|
||||
|
||||
do {
|
||||
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
|
||||
g_current = maybe_next.value();
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#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
|
||||
return ptr;
|
||||
}
|
||||
@ -101,7 +101,7 @@ template <typename T> class DoublyLinkedList
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Result<T*> first()
|
||||
Option<T*> first()
|
||||
{
|
||||
return nonnull_or_error((T*)m_start_node);
|
||||
}
|
||||
@ -111,7 +111,7 @@ template <typename T> class DoublyLinkedList
|
||||
return first().value();
|
||||
}
|
||||
|
||||
Result<T*> last()
|
||||
Option<T*> last()
|
||||
{
|
||||
return nonnull_or_error((T*)m_end_node);
|
||||
}
|
||||
@ -121,12 +121,12 @@ template <typename T> class DoublyLinkedList
|
||||
return last().value();
|
||||
}
|
||||
|
||||
Result<T*> next(T* item)
|
||||
Option<T*> next(T* item)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user