BAN: Add operator-> and operator* to Optional
This commit is contained in:
parent
d0a0e3bdef
commit
16e5f96b1d
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue