LinkedList: Rename the nonnull_or_error() helper to a more accurate nonnull_or_empty_option()

This commit is contained in:
apio 2022-12-30 18:44:37 +01:00
parent 1f36ecd044
commit 28f53f9ccf
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -2,7 +2,7 @@
#include <luna/Option.h>
#include <luna/TypeTraits.h>
template <typename T> inline Option<T*> nonnull_or_error(T* ptr)
template <typename T> inline Option<T*> nonnull_or_empty_option(T* ptr)
{
if (ptr == nullptr) return {};
else
@ -131,7 +131,7 @@ template <typename T> class LinkedList
Option<T*> first()
{
return nonnull_or_error((T*)m_start_node);
return nonnull_or_empty_option((T*)m_start_node);
}
T* expect_first()
@ -142,7 +142,7 @@ template <typename T> class LinkedList
Option<T*> last()
{
return nonnull_or_error((T*)m_end_node);
return nonnull_or_empty_option((T*)m_end_node);
}
T* expect_last()
@ -153,12 +153,12 @@ template <typename T> class LinkedList
Option<T*> next(T* item)
{
return nonnull_or_error((T*)extract_node(item)->get_next());
return nonnull_or_empty_option((T*)extract_node(item)->get_next());
}
Option<T*> previous(T* item)
{
return nonnull_or_error((T*)extract_node(item)->get_last());
return nonnull_or_empty_option((T*)extract_node(item)->get_last());
}
// Iterates over the elements of the LinkedList from start to end, calling callback for every element.