From b0cd732ac768d9bd9466a347ee361acdcc404b90 Mon Sep 17 00:00:00 2001 From: Reece Date: Sun, 27 Mar 2022 19:46:25 +0100 Subject: [PATCH] [*] Update AuTryInsert [*] Fixup AuTryRemove [+] AuAddConst_t --- Include/auROXTL/auContainerUtils.hpp | 300 ++++++++------------------- Include/auROXTL/auTemplateMeta.hpp | 9 + 2 files changed, 101 insertions(+), 208 deletions(-) diff --git a/Include/auROXTL/auContainerUtils.hpp b/Include/auROXTL/auContainerUtils.hpp index 1e1fbac1..72afdc92 100644 --- a/Include/auROXTL/auContainerUtils.hpp +++ b/Include/auROXTL/auContainerUtils.hpp @@ -48,7 +48,7 @@ namespace __audetail }; template - constexpr inline bool AuHastry_emplace_v = AuHastry_emplace::type::value; + constexpr inline bool AuHastry_emplace_v = false;// ::type::value; template struct AuHasemplace @@ -59,18 +59,30 @@ namespace __audetail }; template - constexpr inline bool AuHasemplace_v = AuHasemplace::type::value; + constexpr inline bool AuHasemplace_v = true;//AuHasemplace::type::value; template struct AuHasfind { - template static constexpr AuTrueType Test(decltype(&C::find)); + template static constexpr AuTrueType Test(decltype(static_cast(&C::find))); + template static constexpr AuTrueType Test(decltype(static_cast(&C::find))); template static constexpr AuFalseType Test(...); using type = decltype(Test(0)); }; template constexpr inline bool AuHasfind_v = AuHasfind::type::value; + + template + struct AuHasend + { + template static constexpr AuTrueType Test(decltype(static_cast(&C::end))); + template static constexpr AuFalseType Test(...); + using type = decltype(Test(0)); + }; + + template + constexpr inline bool AuHasend_v = AuHasend::type::value; } template @@ -88,25 +100,6 @@ inline bool AuRemoveIf(T &in, const AuPredicate &> &pre return _AuRemoveIfBase(in, predicate); } -template -inline bool AuTryRemove(T &in, const Z &type) -{ - AUROXTL_COMMODITY_TRY - { - auto itr = in.find(type); - if (itr == in.end()) - { - return false; - } - in.erase(itr); - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } -} - template inline void AuRemove(T &in, const Z &type) { @@ -222,12 +215,6 @@ inline bool AuExists(const Range &a, const Key &key) return std::find(a.begin(), a.end(), key) != a.end(); } -template )> -inline bool AuExists(const Range *a, const Key &key) -{ - return AuExists(*a, key); -} - template )> inline bool AuExists(const Map &map, const Key &key) { @@ -242,7 +229,7 @@ inline bool AuExists(const Map &map, const Key &key) } } -template )> +template inline bool AuExists(const Map *map, const Key &key) { return AuExists(*map, key); @@ -264,11 +251,20 @@ inline bool AuTryFindGeneric(Map &map, const Key &key, Value *&ptr) } } -template -inline bool AuTryFindGeneric(Map &map, const Key &key) +template +inline bool AuTryClear(Container &container) { - if (map.find(key) != map.end()) + container.clear(); + return true; +} + +template )> +inline bool AuTryRemove(Range &list, const Key &key) +{ + auto itr = std::find(list.begin(), list.end(), key); + if (itr != list.end()) { + list.erase(itr); return true; } else @@ -277,15 +273,8 @@ inline bool AuTryFindGeneric(Map &map, const Key &key) } } -template -inline bool AuTryClear(Container &container) -{ - container.clear(); // clears are generally noexcept. - return true; -} - -template -inline bool AuTryDelete(Map &map, const Key &key) +template )> +inline bool AuTryRemove(Map &map, const Key &key) { auto itr = map.find(key); if (itr != map.end()) @@ -299,35 +288,10 @@ inline bool AuTryDelete(Map &map, const Key &key) } } -/// @deprecated -> Should've been named AuTryRemoveList -template -inline bool AuTryDeleteList(List &list, const Key &key) +template +inline bool AuTryRemove(Map *map, const Key &key) { - auto itr = std::find(list.begin(), list.end(), key); - if (itr != list.end()) - { - list.erase(itr); - return true; - } - else - { - return false; - } -} - -template -inline bool AuTryRemoveList(List &list, const Key &key) -{ - auto itr = std::find(list.begin(), list.end(), key); - if (itr != list.end()) - { - list.erase(itr); - return true; - } - else - { - return false; - } + return AuTryRemove(*map, key); } template @@ -398,14 +362,14 @@ inline bool AuTryInsert(Container &container, const Key_t &key, Type_t &&value) #if defined(_AURORA_NULLEXPT_USE_TRY_EMPLACE_AFTER_FIND) if constexpr (__audetail::AuHastry_emplace_v) { - auto [iterator, success] = container.try_emplace(AuForward(key), AuMove(value)); + auto [iterator, success] = container.try_emplace(key, AuMove(value)); return success; } else #endif if constexpr (__audetail::AuHasemplace_v) { - container.emplace(AuForward(key), AuMove(value)); + container.emplace(key, AuMove(value)); return true; } else @@ -425,6 +389,7 @@ inline bool AuTryInsert(Container &container, const Key_t &key, Type_t &&value) } } + template inline bool AuContainerExpandOne(Container &container) { @@ -445,8 +410,8 @@ inline bool AuContainerExpandOne(Container *container) } -template -inline bool AuTryInsert(Container &container, Type &&value) +template )> +inline bool AuTryInsert(Container &container, const Value &value) { AUROXTL_COMMODITY_TRY { @@ -458,6 +423,52 @@ inline bool AuTryInsert(Container &container, Type &&value) } } + container.insert(AuReference(value)); + + return true; + } + AUROXTL_COMMODITY_CATCH + { + return false; + } +} + +template )> +inline bool AuTryInsert(Container &container, Value &&value) +{ + AUROXTL_COMMODITY_TRY + { + if constexpr (__audetail::AuIsPreallocatable_v>) + { + if (!AuContainerExpandOne(container)) + { + return false; + } + } + + container.insert(AuMove(value)); + + return true; + } + AUROXTL_COMMODITY_CATCH + { + return false; + } +} + +template )> +inline bool AuTryInsert(Container &container, Value &&value) +{ + AUROXTL_COMMODITY_TRY + { + if constexpr (__audetail::AuIsPreallocatable_v>) + { + if (!AuContainerExpandOne(container)) + { + return false; + } + } + container.insert(container.end(), AuMove(value)); return true; @@ -468,9 +479,8 @@ inline bool AuTryInsert(Container &container, Type &&value) } } - -template -inline bool AuTryInsert(Container &container, const Type &value) +template )> +inline bool AuTryInsert(Container &container, const Value &value) { AUROXTL_COMMODITY_TRY { @@ -492,142 +502,16 @@ inline bool AuTryInsert(Container &container, const Type &value) } } -template -inline bool AuTryInsert(Container *container, const Type &value) +template +inline bool AuTryInsert(const Map *map, Value &&value) { - AUROXTL_COMMODITY_TRY - { - if constexpr (__audetail::AuIsPreallocatable_v>) - { - if (!AuContainerExpandOne(container)) - { - return false; - } - } - - container->insert(container->end(), value); - - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } + return AuTryInsert(*map, AuMove(value)); } -template -inline bool AuTryInsert(Container *container, Type &&value) +template +inline bool AuTryInsert(const Map *map, const Value &value) { - AUROXTL_COMMODITY_TRY - { - if constexpr (__audetail::AuIsPreallocatable_v>) - { - if (!AuContainerExpandOne(container)) - { - return false; - } - } - - container->insert(container->end(), AuMove(value)); - - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } -} - -template -inline bool AuTryInsertNoEnd(Container &container, Type &&value) // move -{ - AUROXTL_COMMODITY_TRY - { - if constexpr (__audetail::AuIsPreallocatable_v>) - { - if (!AuContainerExpandOne(container)) - { - return false; - } - } - - container.insert(AuMove(value)); - - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } -} - -template -inline bool AuTryInsertNoEnd(Container &container, const Type &value) -{ - AUROXTL_COMMODITY_TRY - { - if constexpr (__audetail::AuIsPreallocatable_v>) - { - if (!AuContainerExpandOne(container)) - { - return false; - } - } - - container.insert(value); - - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } -} - -template -inline bool AuTryInsertNoEnd(Container *container, Type &&value) -{ - AUROXTL_COMMODITY_TRY - { - if constexpr (__audetail::AuIsPreallocatable_v>) - { - if (!AuContainerExpandOne(container)) - { - return false; - } - } - - container->insert(AuMove(value)); - - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } -} - -template -inline bool AuTryInsertNoEnd(Container *container, const Type &value) -{ - AUROXTL_COMMODITY_TRY - { - if constexpr (__audetail::AuIsPreallocatable_v>) - { - if (!AuContainerExpandOne(container)) - { - return false; - } - } - - container->insert(value); - - return true; - } - AUROXTL_COMMODITY_CATCH - { - return false; - } + return AuTryInsert(*map, value); } namespace Aurora::Memory diff --git a/Include/auROXTL/auTemplateMeta.hpp b/Include/auROXTL/auTemplateMeta.hpp index bcc3451d..d987b016 100644 --- a/Include/auROXTL/auTemplateMeta.hpp +++ b/Include/auROXTL/auTemplateMeta.hpp @@ -235,6 +235,15 @@ using AuAddRReference_t = typename AuAddRReference::type; template AuAddRReference_t AuDeclVal(); +template +struct AuAddConst +{ + using type = const T; +}; + +template +using AuAddConst_t = typename AuAddConst::type; + template using AuEnableIf_t = typename AuEnableIf::type;