AuROXTL/Include/auROXTL/auResult.hpp
Reece Wilson dba4a884ca [+] AuTryCall
[+] AuTryCallPair
[+] AuIsCallable
[+] AuIsCallable_v
[*] Improved AuResetMember
2022-11-17 02:28:23 +00:00

73 lines
1.0 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: auResult.hpp
Date: 2022-3-23
Author: Reece
***/
#pragma once
#include "auCopyMoveUtils.hpp"
#include "auHashUtils.hpp"
template <class T>
struct AuResult
{
bool success;
T type;
AuResult() : success(false)
{}
AuResult(bool success) : success(success)
{}
AuResult(T &&value) : type(value), success(true)
{}
// Forced return value optimization.
T &GetResult()
{
return type;
}
constexpr const T *operator->() const
{
return &type;
}
constexpr T *operator->()
{
return &type;
}
const T &GetResult() const
{
return type;
}
void Complete()
{
this->success = true;
}
operator bool() const
{
return this->success;
}
bool has_value() const
{
return this->success;
}
const T &value() const
{
return type;
}
T &value()
{
return type;
}
};