[+] AuCtorErrorTag
This commit is contained in:
parent
dd2bba92e5
commit
a7a982194e
@ -7,10 +7,26 @@
|
|||||||
***/
|
***/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
struct AuCtorCode_t
|
struct AuCtorErrorTag
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
operator bool() const;
|
||||||
|
static constexpr AuCtorCode_t Failed ();
|
||||||
|
static constexpr AuCtorCode_t Success();
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AuCtorCode_t : AuCtorErrorTag
|
||||||
{
|
{
|
||||||
bool value;
|
bool value;
|
||||||
|
|
||||||
|
inline constexpr AuCtorCode_t()
|
||||||
|
{};
|
||||||
|
|
||||||
|
inline constexpr AuCtorCode_t(bool val) : value(val)
|
||||||
|
{};
|
||||||
|
|
||||||
|
|
||||||
operator bool() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
|
@ -7,17 +7,17 @@
|
|||||||
***/
|
***/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define _AU_TRYCONTRUST_CHECKCODE AU_TEMPLATE_ENABLE_WHEN(AuIsSame_v<CtorCode_t, AuCtorCode_t> || AuIsBaseOf_v<AuCtorCode_t, CtorCode_t>)
|
#define _AU_TRYCONTRUST_CHECKCODE AU_TEMPLATE_ENABLE_WHEN(AuIsSame_v<CtorCode_t, AuCtorErrorTag> || AuIsBaseOf_v<AuCtorErrorTag, CtorCode_t>)
|
||||||
|
|
||||||
template <class T, class CtorCode_t = AuCtorCode_t, typename ... Args, _AU_TRYCONTRUST_CHECKCODE>
|
template <class T, class CtorCode_t = AuCtorCode_t, typename ... Args, _AU_TRYCONTRUST_CHECKCODE>
|
||||||
inline T AuTryConstruct(CtorCode_t &status, Args&& ... args)
|
inline T AuTryConstruct(CtorCode_t &status, Args&& ... args)
|
||||||
{
|
{
|
||||||
if constexpr (AuIsConstructible_v<T, AuCtorCode_t &, Args ...>)
|
if constexpr (AuIsConstructible_v<T, CtorCode_t &, Args ...>)
|
||||||
{
|
{
|
||||||
status = CtorCode_t::Failed();
|
status = CtorCode_t::Failed();
|
||||||
return T(AuReference(status), AuForward<T>(args)...);
|
return T(AuReference(status), AuForward<T>(args)...);
|
||||||
}
|
}
|
||||||
else if constexpr (AuIsConstructible_v<T, Args ..., AuCtorCode_t &>)
|
else if constexpr (AuIsConstructible_v<T, Args ..., CtorCode_t &>)
|
||||||
{
|
{
|
||||||
status = CtorCode_t::Failed();
|
status = CtorCode_t::Failed();
|
||||||
return T(AuForward<T>(args)..., AuReference(status));
|
return T(AuForward<T>(args)..., AuReference(status));
|
||||||
|
Loading…
Reference in New Issue
Block a user