From cb6bf3ec74bbcf647a36bf9251602b7e170a1382 Mon Sep 17 00:00:00 2001 From: Jamie Reece Wilson Date: Fri, 1 Mar 2024 22:33:50 +0000 Subject: [PATCH] [+] AuClamp and AuInvoke --- Include/auROXTL/AU_Z.hpp | 9 +- Include/auROXTL/auNumberUtils.hpp | 98 ++++++++++++++- Include/auROXTL/auOptional.hpp | 29 ++--- Include/auROXTL/auOptionalEx.hpp | 91 +------------- Include/auROXTL/auTemplateMeta.hpp | 190 ++++++++++++++++++++++++----- 5 files changed, 267 insertions(+), 150 deletions(-) diff --git a/Include/auROXTL/AU_Z.hpp b/Include/auROXTL/AU_Z.hpp index e3cec57..944fe72 100644 --- a/Include/auROXTL/AU_Z.hpp +++ b/Include/auROXTL/AU_Z.hpp @@ -11,7 +11,7 @@ // Exception model //////////////////////////////////////////////////////////////////////////////////////////////// -#if !defined(AUROXTL_NO_TRY) +#if !defined(AUROXTL_NO_TRY) && !defined(AURORA_ROXTL_NO_TRY) #define AUROXTL_COMMODITY_TRY try #define AUROXTL_COMMODITY_CATCH catch (...) #else @@ -19,6 +19,13 @@ #define AUROXTL_COMMODITY_CATCH while (0) #endif +#if !defined(AUROXTL_NO_CONSTEXPR) && !defined(AURORA_ROXTL_NO_CONSTEXPR) + #define AUROXTL_CONSTEXPR constexpr +#else + #define AUROXTL_CONSTEXPR +#endif + + //////////////////////////////////////////////////////////////////////////////////////////////// // Stinky container config (leave it alone) //////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Include/auROXTL/auNumberUtils.hpp b/Include/auROXTL/auNumberUtils.hpp index 1b2f390..124a201 100644 --- a/Include/auROXTL/auNumberUtils.hpp +++ b/Include/auROXTL/auNumberUtils.hpp @@ -9,32 +9,32 @@ template , A, AuCommonType_t>> -constexpr Ret_t AuMin(const A &a, const B &b) +AUROXTL_CONSTEXPR Ret_t AuMin(const A &a, const B &b) { return a < b ? a : b; } template , A, AuCommonType_t>> -constexpr Ret_t AuMax(const A &a, const B &b) +AUROXTL_CONSTEXPR Ret_t AuMax(const A &a, const B &b) { return a < b ? b : a; } template -constexpr const T AuConstPow(const T base, const AuUInt8 exponent) +AUROXTL_CONSTEXPR const T AuConstPow(const T base, const AuUInt8 exponent) { return exponent ? base * AuConstPow(base, exponent - 1) : 1; } template -constexpr const T AuPageRoundUp(const T value, const T pageSize) +AUROXTL_CONSTEXPR const T AuPageRoundUp(const T value, const T pageSize) { return (value + (pageSize - 1)) & ~(pageSize - 1); } template -constexpr const T AuPageRound(const T value, const T pageSize) +AUROXTL_CONSTEXPR const T AuPageRound(const T value, const T pageSize) { return value & ~(pageSize - 1); } @@ -94,4 +94,92 @@ const T AuRoundDownPow2(const T value) AuBitScanReverse(ret, value); return T(1) << T(ret); } +} + +namespace AuHash +{ + template + struct less; + + template + struct equal; +} + +template +struct AuLess +{ +// intentionally not constexpr (but it should compile down to nothing) + bool operator()(const T &lhs, const T &rhs) const + { + return (AuHash::less {})(lhs, rhs); + } +}; + +template <> +struct AuLess +{ +// intentionally not constexpr (but it should compile down to nothing) + template + bool operator()(const T &lhs, const T &rhs) const + { + return (AuHash::less {})(lhs, rhs); + } +}; + +template +struct AuGreater +{ +// intentionally not constexpr (but it should compile down to nothing) + bool operator()(const T &lhs, const T &rhs) const + { + return !((AuHash::equal {})(lhs, rhs)) && + !((AuHash::less {})(lhs, rhs)); + } +}; + +template <> +struct AuGreater +{ +// intentionally not constexpr (but it should compile down to nothing) + template + bool operator()(const T &lhs, const T &rhs) const + { + return !((AuHash::equal {})(lhs, rhs)) && + !((AuHash::less {})(lhs, rhs)); + } +}; + +template +struct AuEqual +{ +// intentionally not constexpr (but it should compile down to nothing) + bool operator()(const T &lhs, const T &rhs) const + { + return (AuHash::equal {})(lhs, rhs); + } +}; + +template <> +struct AuEqual +{ +// intentionally not constexpr (but it should compile down to nothing) + template + bool operator()(const T &lhs, const T &rhs) const + { + return (AuHash::equal {})(lhs, rhs); + } +}; + +// intentionally not constexpr (but it should compile down to nothing) +template +const T &AuClamp(const T &v, const T &lo, const T &hi) +{ + return AuClamp(v, lo, hi, AuLess {}); +} + +// intentionally not constexpr (but it should compile down to nothing) +template +const T &AuClamp(const T &v, const T &lo, const T &hi, Compare comp) +{ + return comp(v, lo) ? lo : comp(hi, v) ? hi : v; } \ No newline at end of file diff --git a/Include/auROXTL/auOptional.hpp b/Include/auROXTL/auOptional.hpp index 7215d12..7704cc5 100644 --- a/Include/auROXTL/auOptional.hpp +++ b/Include/auROXTL/auOptional.hpp @@ -4,33 +4,18 @@ File: auOptional.hpp Date: 2022-2-1 Author: Reece + Warning: deprecated ***/ #pragma once +#include "ThirdParty/tartanllamaOptional.hpp" -#if defined(DO_NOT_USEtartanllama) - - #if !defined(AURORA_RUNTIME_AU_OPTIONAL) - #define AURORA_RUNTIME_AU_OPTIONAL std::optional - #endif - -#else - - #include "ThirdParty/tartanllamaOptional.hpp" - - #if !defined(AURORA_RUNTIME_AU_OPTIONAL) - #define AURORA_RUNTIME_AU_OPTIONAL tl::optional - #endif - -#endif - -#if defined(_AURORA_AVOID_DUMB_STL_TYPES) - template - using AuOptional = AuOptionalEx; -#else - template - using AuOptional = AURORA_RUNTIME_AU_OPTIONAL; +#if !defined(AURORA_RUNTIME_AU_OPTIONAL) + #define AURORA_RUNTIME_AU_OPTIONAL tl::optional #endif +template +using AuOptional = AURORA_RUNTIME_AU_OPTIONAL; + template constexpr inline bool AuIsOptional_v = __audetail::AuHashas_value_v; diff --git a/Include/auROXTL/auOptionalEx.hpp b/Include/auROXTL/auOptionalEx.hpp index 9c753a5..6abd3d8 100644 --- a/Include/auROXTL/auOptionalEx.hpp +++ b/Include/auROXTL/auOptionalEx.hpp @@ -4,104 +4,15 @@ File: auOptionalEx.hpp Date: 2022-3-23 Author: Reece + Warning: deprecated ***/ #pragma once #include "auCopyMoveUtils.hpp" #include "auHashUtils.hpp" -#if defined(DO_NOT_USEtartanllama) - -// @DEPRECATED -// WONT FINISH, probably -// Use forked tartanllama optional instead (aurora should compile with either) -template -struct AuOptionalEx -{ - bool hasValue; - T type; - - AuOptionalEx() : hasValue(false) - {} - - AuOptionalEx(const 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) ? value() : static_cast(AuForward(defaultValue)); - - } - template - constexpr T ValueOr(U &&defaultValue) && - { - return bool(*this) ? AuMove(value()) : static_cast(AuForward(defaultValue)); - } - - bool HasValue() const - { - return this->hasValue; - } - - operator bool() const - { - return this->hasValue; - } - - T &value() - { - return this->type; - } - - const T &value() const - { - return this->type; - } - - bool has_value() const - { - return this->hasValue; - } - - AuUInt HashCode() const - { - return AuHashCode(type); - } - - void Reset() - { - this->type = {}; - this->hasValue = {}; - } - - void Swap(AuOptionalEx &&ex) - { - AuSwap(this->type, ex.type); - AuSwap(this->hasValue, ex.hasValue); - } - - // TODO finish me -}; - -#else #include "ThirdParty/tartanllamaOptional.hpp" template using AuOptionalEx = tl::optional; - -#endif diff --git a/Include/auROXTL/auTemplateMeta.hpp b/Include/auROXTL/auTemplateMeta.hpp index 71164cc..86cf4e0 100644 --- a/Include/auROXTL/auTemplateMeta.hpp +++ b/Include/auROXTL/auTemplateMeta.hpp @@ -4,22 +4,23 @@ File: auTemplateMeta.hpp Date: 2022-2-1 Author: Reece + Note: most of this code assumes C++17 or greater ***/ #pragma once template struct AuBoolType { - static constexpr bool value = v; + static AUROXTL_CONSTEXPR bool value = v; using value_type = bool; using type = AuBoolType; - constexpr operator value_type() const noexcept + AUROXTL_CONSTEXPR operator value_type() const noexcept { return value; } - constexpr value_type operator()() const noexcept + AUROXTL_CONSTEXPR value_type operator()() const noexcept { return value; } @@ -56,13 +57,13 @@ struct AuIsSame : AuTrueType {}; template -inline constexpr bool AuIsSame_v = AuIsSame::value; +inline AUROXTL_CONSTEXPR bool AuIsSame_v = AuIsSame::value; template -inline constexpr bool AuIsConst_v = false; +inline AUROXTL_CONSTEXPR bool AuIsConst_v = false; template -inline constexpr bool AuIsConst_v = true; +inline AUROXTL_CONSTEXPR bool AuIsConst_v = true; namespace _audetail { @@ -93,7 +94,7 @@ struct AuIsClass : decltype(_audetail::IsClass(nullptr)) {}; template -inline constexpr bool AuIsClass_v = AuIsClass::value; +inline AUROXTL_CONSTEXPR bool AuIsClass_v = AuIsClass::value; template struct AuIsBaseOf : @@ -105,43 +106,43 @@ struct AuIsBaseOf : {}; template -inline constexpr bool AuIsBaseOf_v = AuIsBaseOf::value; +inline AUROXTL_CONSTEXPR bool AuIsBaseOf_v = AuIsBaseOf::value; template -inline constexpr bool AuIsPointer_v = false; +inline AUROXTL_CONSTEXPR bool AuIsPointer_v = false; template -inline constexpr bool AuIsPointer_v = true; +inline AUROXTL_CONSTEXPR bool AuIsPointer_v = true; template -inline constexpr bool AuIsPointer_v = true; +inline AUROXTL_CONSTEXPR bool AuIsPointer_v = true; template -inline constexpr bool AuIsPointer_v = true; +inline AUROXTL_CONSTEXPR bool AuIsPointer_v = true; template -inline constexpr bool AuIsPointer_v = true; +inline AUROXTL_CONSTEXPR bool AuIsPointer_v = true; template -inline constexpr bool AuIsReference_v = false; +inline AUROXTL_CONSTEXPR bool AuIsReference_v = false; template -inline constexpr bool AuIsReference_v = true; +inline AUROXTL_CONSTEXPR bool AuIsReference_v = true; template -inline constexpr bool AuIsReference_v = true; +inline AUROXTL_CONSTEXPR bool AuIsReference_v = true; template -inline constexpr bool AuIsLValueReference_v = false; +inline AUROXTL_CONSTEXPR bool AuIsLValueReference_v = false; template -inline constexpr bool AuIsLValueReference_v = true; +inline AUROXTL_CONSTEXPR bool AuIsLValueReference_v = true; template -inline constexpr bool AuIsRValueReference_v = false; +inline AUROXTL_CONSTEXPR bool AuIsRValueReference_v = false; template -inline constexpr bool AuIsRValueReference_v = true; +inline AUROXTL_CONSTEXPR bool AuIsRValueReference_v = true; template struct AuRemovePointer @@ -180,7 +181,7 @@ template using AuIsVoid = AuIsSame; template -inline constexpr bool AuIsVoid_v = AuIsVoid::value; +inline AUROXTL_CONSTEXPR bool AuIsVoid_v = AuIsVoid::value; template struct AuRemoveReference @@ -310,13 +311,13 @@ template using AuVoid_t = void; template -constexpr inline bool AuIsArray_v = false; +AUROXTL_CONSTEXPR inline bool AuIsArray_v = false; template -inline constexpr bool AuIsArray_v = true; +inline AUROXTL_CONSTEXPR bool AuIsArray_v = true; template -inline constexpr bool AuIsArray_v = true; +inline AUROXTL_CONSTEXPR bool AuIsArray_v = true; template using AuEnableIf_t = typename AuEnableIf::type; @@ -324,8 +325,8 @@ using AuEnableIf_t = typename AuEnableIf::type; template struct AuIsConstructible { - template static constexpr AuTrueType Test(decltype(::new C(AuDeclVal()...))); - template static constexpr AuFalseType Test(...); + template static AUROXTL_CONSTEXPR AuTrueType Test(decltype(::new C(AuDeclVal()...))); + template static AUROXTL_CONSTEXPR AuFalseType Test(...); using type = decltype(Test(0)); }; @@ -333,7 +334,7 @@ template using AuIsConstructible_t = typename AuIsConstructible::type; template -inline constexpr bool AuIsConstructible_v = AuIsConstructible::type::value; +inline AUROXTL_CONSTEXPR bool AuIsConstructible_v = AuIsConstructible::type::value; template struct AuConditional @@ -371,8 +372,8 @@ template