diff --git a/Include/auROXTL/auTryConstruct.hpp b/Include/auROXTL/auTryConstruct.hpp index ee87c448..b2731769 100644 --- a/Include/auROXTL/auTryConstruct.hpp +++ b/Include/auROXTL/auTryConstruct.hpp @@ -7,69 +7,15 @@ ***/ #pragma once -template -inline T AuTryConstruct(AuCtorCode_t &status, Args&& ... args) +struct AuCtorCode_t { - if constexpr (AuIsConstructible::type::value) - { - status = AuCtorCode_t::Failed(); - return T(status, AuForward(args)...); - } - else - { - try - { - status = AuCtorCode_t::Success(); - return T(AuForward(args)...); - } - catch (...) - { - status = AuCtorCode_t::Failed(); - return T(); - } - } -} + bool value; -template -inline AuPair AuTryConstructPair(Args&& ... args) -{ - AuCtorCode_t code; - T object = AuTryConstruct(AuReference(code), AuForward(args)...); - return AuMakePair(AuMove(code), AuMove(object)); -} - -template -inline T AuTryConstructWithDefault(AuCtorCode_t &status, T &&def, Args&& ... args) -{ - if constexpr (AuIsConstructible::type::value) + operator bool() const { - status = AuCtorCode_t::Failed(); - T returnValue = T(status, AuForward(args)...); - if (!status) - { - return AuMove(def); - } - return returnValue; + return value; } - else - { - try - { - status = AuCtorCode_t::Success(); - return T(AuForward(args)...); - } - catch (...) - { - status = AuCtorCode_t::Failed(); - return AuMove(def); - } - } -} -template -inline AuPair AuTryConstructWithDefaultPair(T &&def, Args&& ... args) -{ - AuCtorCode_t code; - T object = AuTryConstructWithDefault(AuReference(code), AuFoward(def), AuForward(args)...); - return AuMakePair(AuMove(code), AuMove(object)); -} \ No newline at end of file + static constexpr AuCtorCode_t Failed () { return AuCtorCode_t {false}; } + static constexpr AuCtorCode_t Success() { return AuCtorCode_t {true}; } +}; \ No newline at end of file diff --git a/Include/auROXTL/auTryConstructUtils.hpp b/Include/auROXTL/auTryConstructUtils.hpp new file mode 100644 index 00000000..ee87c448 --- /dev/null +++ b/Include/auROXTL/auTryConstructUtils.hpp @@ -0,0 +1,75 @@ +/*** + Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: auTryConstruct.hpp + Date: 2022-3-25 + Author: Reece +***/ +#pragma once + +template +inline T AuTryConstruct(AuCtorCode_t &status, Args&& ... args) +{ + if constexpr (AuIsConstructible::type::value) + { + status = AuCtorCode_t::Failed(); + return T(status, AuForward(args)...); + } + else + { + try + { + status = AuCtorCode_t::Success(); + return T(AuForward(args)...); + } + catch (...) + { + status = AuCtorCode_t::Failed(); + return T(); + } + } +} + +template +inline AuPair AuTryConstructPair(Args&& ... args) +{ + AuCtorCode_t code; + T object = AuTryConstruct(AuReference(code), AuForward(args)...); + return AuMakePair(AuMove(code), AuMove(object)); +} + +template +inline T AuTryConstructWithDefault(AuCtorCode_t &status, T &&def, Args&& ... args) +{ + if constexpr (AuIsConstructible::type::value) + { + status = AuCtorCode_t::Failed(); + T returnValue = T(status, AuForward(args)...); + if (!status) + { + return AuMove(def); + } + return returnValue; + } + else + { + try + { + status = AuCtorCode_t::Success(); + return T(AuForward(args)...); + } + catch (...) + { + status = AuCtorCode_t::Failed(); + return AuMove(def); + } + } +} + +template +inline AuPair AuTryConstructWithDefaultPair(T &&def, Args&& ... args) +{ + AuCtorCode_t code; + T object = AuTryConstructWithDefault(AuReference(code), AuFoward(def), AuForward(args)...); + return AuMakePair(AuMove(code), AuMove(object)); +} \ No newline at end of file diff --git a/Include/auROXTL/auUnitUtils.hpp b/Include/auROXTL/auUnitUtils.hpp index 7fe03b86..7f415677 100644 --- a/Include/auROXTL/auUnitUtils.hpp +++ b/Include/auROXTL/auUnitUtils.hpp @@ -7,6 +7,15 @@ ***/ #pragma once +/** + It is not unusual for one to desire a unit-conversion constant when the developer understands + [*] FPU isn't available + [*] Can be done quickly without a framework + [*] Using a framework to normalize to a base unit, apply a translation, and return the desired reuslt is considered overkill + These functions are not to be converted into such a convoluted templated potentially-constexpr castable mess + The intention is to keep these utility functions as simple as the dumb operations they implement +*/ + template constexpr const Inch AuFeetToInch(Feet feet) { diff --git a/Include/auROXTLTypes.hpp b/Include/auROXTLTypes.hpp index 83f703b4..82258be2 100644 --- a/Include/auROXTLTypes.hpp +++ b/Include/auROXTLTypes.hpp @@ -26,6 +26,7 @@ #endif #include +#include #include #include #include diff --git a/Include/auROXTLUtils.hpp b/Include/auROXTLUtils.hpp index 2c980a00..c98dff3d 100644 --- a/Include/auROXTLUtils.hpp +++ b/Include/auROXTLUtils.hpp @@ -27,6 +27,7 @@ #include #endif + #include #include #include @@ -44,22 +45,7 @@ #include #include #include - -template -inline T AuTryConstruct(bool &status, Args&& ... args) -{ - T t; - try - { - t = T(AuForward(args)...); - status = true; - } - catch (...) - { - status = false; - } - return t; -} +#include struct IAuNullDelegate