2022-03-23 16:03:48 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: auOptionalEx.hpp
|
|
|
|
Date: 2022-3-23
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "auCopyMoveUtils.hpp"
|
|
|
|
#include "auHashUtils.hpp"
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
struct AuOptionalEx
|
|
|
|
{
|
|
|
|
const bool hasValue;
|
|
|
|
T type;
|
|
|
|
|
|
|
|
AuOptionalEx() : hasValue({})
|
|
|
|
{}
|
|
|
|
|
|
|
|
AuOptionalEx(T &value) : type(value), hasValue(true)
|
|
|
|
{}
|
|
|
|
|
|
|
|
AuOptionalEx(T &&value) : type(value), hasValue(true)
|
|
|
|
{}
|
|
|
|
|
|
|
|
T &Value()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const T &Value() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class U>
|
|
|
|
constexpr T ValueOr(U &&defaultValue) const &
|
|
|
|
{
|
2022-03-23 18:51:15 +00:00
|
|
|
return bool(*this) ? value() : static_cast<T>(AuForward<U>(defaultValue));
|
2022-03-23 16:03:48 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
template<class U>
|
|
|
|
constexpr T ValueOr(U &&defaultValue) &&
|
|
|
|
{
|
2022-03-23 18:51:15 +00:00
|
|
|
return bool(*this) ? AuMove(value()) : static_cast<T>(AuForward<U>(defaultValue));
|
2022-03-23 16:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HasValue() const
|
|
|
|
{
|
|
|
|
return this->hasValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return this->hasValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
T &value()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const T &value() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_value() const
|
|
|
|
{
|
|
|
|
return this->hasValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuUInt HashCode() const
|
|
|
|
{
|
|
|
|
return AuHashCode(type);
|
|
|
|
}
|
|
|
|
};
|