/*** 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 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 constexpr T ValueOr(U &&defaultValue) const & { return bool(*this) ? **this : static_cast(AuForward(defaultValue)); } template constexpr T ValueOr(U &&defaultValue) && { return bool(*this) ? AuMove(**this) : static_cast(AuForward(defaultValue)); } 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); } };