[*] Update AuTryInsert
[*] Fixup AuTryRemove [+] AuAddConst_t
This commit is contained in:
parent
3c23be4ea1
commit
b0cd732ac7
@ -48,7 +48,7 @@ namespace __audetail
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuHastry_emplace_v = AuHastry_emplace<T>::type::value;
|
||||
constexpr inline bool AuHastry_emplace_v = false;// <T>::type::value;
|
||||
|
||||
template <class T>
|
||||
struct AuHasemplace
|
||||
@ -59,18 +59,30 @@ namespace __audetail
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuHasemplace_v = AuHasemplace<T>::type::value;
|
||||
constexpr inline bool AuHasemplace_v = true;//AuHasemplace<T>::type::value;
|
||||
|
||||
template <class T>
|
||||
struct AuHasfind
|
||||
{
|
||||
template <class C> static constexpr AuTrueType Test(decltype(&C::find));
|
||||
template <class C> static constexpr AuTrueType Test(decltype(static_cast<C::const_iterator(C:: *)(const C::key_type &) const>(&C::find)));
|
||||
template <class C> static constexpr AuTrueType Test(decltype(static_cast<C::const_iterator(C:: *)(const C::element_type &) const>(&C::find)));
|
||||
template <class C> static constexpr AuFalseType Test(...);
|
||||
using type = decltype(Test<T>(0));
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuHasfind_v = AuHasfind<T>::type::value;
|
||||
|
||||
template <class T>
|
||||
struct AuHasend
|
||||
{
|
||||
template <class C> static constexpr AuTrueType Test(decltype(static_cast<C::const_iterator(C:: *)() const>(&C::end)));
|
||||
template <class C> static constexpr AuFalseType Test(...);
|
||||
using type = decltype(Test<T>(0));
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuHasend_v = AuHasend<T>::type::value;
|
||||
}
|
||||
|
||||
template <class T, bool all>
|
||||
@ -88,25 +100,6 @@ inline bool AuRemoveIf(T &in, const AuPredicate<const AuToValueType_t<T> &> &pre
|
||||
return _AuRemoveIfBase<T, false>(in, predicate);
|
||||
}
|
||||
|
||||
template <class T, typename Z>
|
||||
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 <class T, typename Z>
|
||||
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 <class Range, class Key, AU_TEMPLATE_ENABLE_WHEN(!__audetail::AuHasfind_v<Range>)>
|
||||
inline bool AuExists(const Range *a, const Key &key)
|
||||
{
|
||||
return AuExists(*a, key);
|
||||
}
|
||||
|
||||
template <class Map, class Key, AU_TEMPLATE_ENABLE_WHEN(__audetail::AuHasfind_v<Map>)>
|
||||
inline bool AuExists(const Map &map, const Key &key)
|
||||
{
|
||||
@ -242,7 +229,7 @@ inline bool AuExists(const Map &map, const Key &key)
|
||||
}
|
||||
}
|
||||
|
||||
template <class Map, class Key, AU_TEMPLATE_ENABLE_WHEN(__audetail::AuHasfind_v<Map>)>
|
||||
template <class Map, class Key>
|
||||
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 <class Map, class Key>
|
||||
inline bool AuTryFindGeneric(Map &map, const Key &key)
|
||||
template <class Container>
|
||||
inline bool AuTryClear(Container &container)
|
||||
{
|
||||
if (map.find(key) != map.end())
|
||||
container.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Range, class Key, AU_TEMPLATE_ENABLE_WHEN(!__audetail::AuHasfind_v<Range>)>
|
||||
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 <class Container>
|
||||
inline bool AuTryClear(Container &container)
|
||||
{
|
||||
container.clear(); // clears are generally noexcept.
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Map, class Key>
|
||||
inline bool AuTryDelete(Map &map, const Key &key)
|
||||
template <class Map, class Key, AU_TEMPLATE_ENABLE_WHEN(__audetail::AuHasfind_v<Map>)>
|
||||
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 <class List, class Key>
|
||||
inline bool AuTryDeleteList(List &list, const Key &key)
|
||||
template <class Map, class Key>
|
||||
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 <class List, class Key>
|
||||
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 <AuUInt N, typename List, class Key>
|
||||
@ -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<Container>)
|
||||
{
|
||||
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>)
|
||||
{
|
||||
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 <class Container>
|
||||
inline bool AuContainerExpandOne(Container &container)
|
||||
{
|
||||
@ -445,8 +410,8 @@ inline bool AuContainerExpandOne(Container *container)
|
||||
}
|
||||
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsert(Container &container, Type &&value)
|
||||
template <class Container, typename Value, AU_TEMPLATE_ENABLE_WHEN(!__audetail::AuHasend_v<Container>)>
|
||||
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 <class Container, typename Value, AU_TEMPLATE_ENABLE_WHEN(!__audetail::AuHasend_v<Container>)>
|
||||
inline bool AuTryInsert(Container &container, Value &&value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container.insert(AuMove(value));
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Value, AU_TEMPLATE_ENABLE_WHEN(__audetail::AuHasend_v<Container>)>
|
||||
inline bool AuTryInsert(Container &container, Value &&value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
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 <class Container, typename Type>
|
||||
inline bool AuTryInsert(Container &container, const Type &value)
|
||||
template <class Container, typename Value, AU_TEMPLATE_ENABLE_WHEN(__audetail::AuHasend_v<Container>)>
|
||||
inline bool AuTryInsert(Container &container, const Value &value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
@ -492,142 +502,16 @@ inline bool AuTryInsert(Container &container, const Type &value)
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsert(Container *container, const Type &value)
|
||||
template <class Map, class Value>
|
||||
inline bool AuTryInsert(const Map *map, Value &&value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container->insert(container->end(), value);
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return AuTryInsert(*map, AuMove(value));
|
||||
}
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsert(Container *container, Type &&value)
|
||||
template <class Map, class Value>
|
||||
inline bool AuTryInsert(const Map *map, const Value &value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container->insert(container->end(), AuMove(value));
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsertNoEnd(Container &container, Type &&value) // move
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container.insert(AuMove(value));
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsertNoEnd(Container &container, const Type &value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container.insert(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsertNoEnd(Container *container, Type &&value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container->insert(AuMove(value));
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Type>
|
||||
inline bool AuTryInsertNoEnd(Container *container, const Type &value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
if constexpr (__audetail::AuIsPreallocatable_v<AuRemoveReference_t<Container>>)
|
||||
{
|
||||
if (!AuContainerExpandOne(container))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
container->insert(value);
|
||||
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return AuTryInsert(*map, value);
|
||||
}
|
||||
|
||||
namespace Aurora::Memory
|
||||
|
@ -235,6 +235,15 @@ using AuAddRReference_t = typename AuAddRReference<T>::type;
|
||||
template <class T>
|
||||
AuAddRReference_t<T> AuDeclVal();
|
||||
|
||||
template <class T>
|
||||
struct AuAddConst
|
||||
{
|
||||
using type = const T;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using AuAddConst_t = typename AuAddConst<T>::type;
|
||||
|
||||
template <bool Test, class T = void>
|
||||
using AuEnableIf_t = typename AuEnableIf<Test, T>::type;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user