BAN: Add operator-> and operator* to Optional

This commit is contained in:
Bananymous 2023-06-12 22:18:12 +03:00
parent d0a0e3bdef
commit 16e5f96b1d
1 changed files with 35 additions and 1 deletions

View File

@ -20,6 +20,12 @@ namespace BAN
Optional& operator=(const Optional&);
Optional& operator=(Optional&&);
T* operator->();
const T* operator->() const;
T& operator*();
const T& operator*() const;
bool has_value() const;
T&& release_value();
@ -76,10 +82,38 @@ namespace BAN
if (other.has_value)
{
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>
bool Optional<T>::has_value() const
{