BAN: Add operator-> and operator* to Optional

This commit is contained in:
Bananymous 2023-06-12 22:18:12 +03:00
parent 326a30d1af
commit 97638f7ade
1 changed files with 35 additions and 1 deletions

View File

@ -20,6 +20,12 @@ namespace BAN
Optional& operator=(const Optional&); Optional& operator=(const Optional&);
Optional& operator=(Optional&&); Optional& operator=(Optional&&);
T* operator->();
const T* operator->() const;
T& operator*();
const T& operator*() const;
bool has_value() const; bool has_value() const;
T&& release_value(); T&& release_value();
@ -76,10 +82,38 @@ namespace BAN
if (other.has_value) if (other.has_value)
{ {
m_has_value = true; m_has_value = true;
new (m_storage) T(BAN::move(other.relase_value())); new (m_storage) T(BAN::move(other.release_value()));
} }
} }
template<typename T>
T* Optional<T>::operator->()
{
ASSERT(has_value());
return &value();
}
template<typename T>
const T* Optional<T>::operator->() const
{
ASSERT(has_value());
return &value();
}
template<typename T>
T& Optional<T>::operator*()
{
ASSERT(has_value());
return value();
}
template<typename T>
const T& Optional<T>::operator*() const
{
ASSERT(has_value());
return value();
}
template<typename T> template<typename T>
bool Optional<T>::has_value() const bool Optional<T>::has_value() const
{ {