Reece Wilson
dba4a884ca
[+] AuTryCallPair [+] AuIsCallable [+] AuIsCallable_v [*] Improved AuResetMember
73 lines
1.0 KiB
C++
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;
|
|
}
|
|
}; |