[+] AuListFromArgs
[*] Amend auTryConstructUtils [+] try_emplace awareness
This commit is contained in:
parent
4d58e98543
commit
1f125e3d8b
@ -69,3 +69,5 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//#define _AURORA_NULLEXPT_USE_TRY_EMPLACE_AFTER_FIND
|
@ -290,7 +290,6 @@ inline bool AuTryRemoveByTupleN(List &list, const Key &key)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
namespace __audetail
|
||||
{
|
||||
template <class T>
|
||||
@ -304,7 +303,6 @@ namespace __audetail
|
||||
template <class T>
|
||||
constexpr inline bool AuHascapacity_v = AuHascapacity<T>::type::value;
|
||||
|
||||
|
||||
template <class T>
|
||||
struct AuHasreserve
|
||||
{
|
||||
@ -318,6 +316,28 @@ namespace __audetail
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuIsPreallocatable_v = AuHascapacity_v<T> && AuHasreserve_v<T>;
|
||||
|
||||
template <class T>
|
||||
struct AuHastry_emplace
|
||||
{
|
||||
template <class C> static constexpr AuTrueType Test(decltype(&C::try_emplace));
|
||||
template <class C> static constexpr AuFalseType Test(...);
|
||||
using type = decltype(Test<T>(0));
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuHastry_emplace_v = AuHastry_emplace<T>::type::value;
|
||||
|
||||
template <class T>
|
||||
struct AuHasemplace
|
||||
{
|
||||
template <class C> static constexpr AuTrueType Test(decltype(&C::emplace));
|
||||
template <class C> static constexpr AuFalseType Test(...);
|
||||
using type = decltype(Test<T>(0));
|
||||
};
|
||||
|
||||
template <class T>
|
||||
constexpr inline bool AuHasemplace_v = AuHasemplace<T>::type::value;
|
||||
}
|
||||
|
||||
template <class Container, typename Key_t, typename Type_t>
|
||||
@ -328,7 +348,61 @@ inline bool AuTryInsert(Container &container, Key_t &&key, Type_t &&value)
|
||||
auto itr = container.find(key);
|
||||
if (itr == container.end())
|
||||
{
|
||||
container.insert(AuMakePair(AuMove(key), AuMove(value)));
|
||||
#if defined(_AURORA_NULLEXPT_USE_TRY_EMPLACE_AFTER_FIND)
|
||||
if constexpr (__audetail::AuHastry_emplace_v<Container>)
|
||||
{
|
||||
auto [iterator, success] = container.try_emplace(AuMove(key), AuMove(value));
|
||||
return success;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if constexpr (__audetail::AuHasemplace_v<Container>)
|
||||
{
|
||||
container.emplace(AuMove(key), AuMove(value));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
container.insert(AuMakePair(AuMove(key), AuMove(value)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
itr->second = value;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
AUROXTL_COMMODITY_CATCH
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Container, typename Key_t, typename Type_t>
|
||||
inline bool AuTryInsert(Container &container, const Key_t &key, Type_t &&value)
|
||||
{
|
||||
AUROXTL_COMMODITY_TRY
|
||||
{
|
||||
auto itr = container.find(key);
|
||||
if (itr == container.end())
|
||||
{
|
||||
#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));
|
||||
return success;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if constexpr (__audetail::AuHasemplace_v<Container>)
|
||||
{
|
||||
container.emplace(AuForward(key), AuMove(value));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
container.insert(AuMakePair(key, AuMove(value)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -47,7 +47,8 @@ namespace AuHash
|
||||
};
|
||||
|
||||
#define _HASH_F_CPP(type) \
|
||||
template <> struct hash<type> \
|
||||
template <> \
|
||||
struct hash<type> \
|
||||
{ \
|
||||
constexpr AuUInt operator ()(const type b) const \
|
||||
{ \
|
||||
|
22
Include/auROXTL/auListUtils.hpp
Normal file
22
Include/auROXTL/auListUtils.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
/***
|
||||
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
||||
|
||||
File: auListUtils.hpp
|
||||
Date: 2022-3-27
|
||||
Author: Reece
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
template <typename T, typename ... Args>
|
||||
constexpr bool AuListFromArgs(T &list, Args && ... args)
|
||||
{
|
||||
constexpr auto end = sizeof...(Args);
|
||||
if (!AuTryResize(list, end))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AuUInt i = 0;
|
||||
(..., (list[i++] = AuMove(args)));
|
||||
return true;
|
||||
}
|
@ -15,19 +15,19 @@ inline T AuTryConstruct(CtorCode_t &status, Args&& ... args)
|
||||
if constexpr (AuIsConstructible_v<T, CtorCode_t &, Args ...>)
|
||||
{
|
||||
status = CtorCode_t::Failed();
|
||||
return T(AuReference(status), AuForward<T>(args)...);
|
||||
return T(AuReference(status), AuForward<Args>(args)...);
|
||||
}
|
||||
else if constexpr (AuIsConstructible_v<T, Args ..., CtorCode_t &>)
|
||||
{
|
||||
status = CtorCode_t::Failed();
|
||||
return T(AuForward<T>(args)..., AuReference(status));
|
||||
return T(AuForward<Args>(args)..., AuReference(status));
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
status = CtorCode_t::Success();
|
||||
return T(AuForward<T>(args)...);
|
||||
return T(AuForward<Args>(args)...);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -51,7 +51,7 @@ inline T AuTryConstructWithDefault(CtorCode_t &status, T &&def, Args&& ... args)
|
||||
if constexpr (AuIsConstructible_v<T, CtorCode_t &, Args ...>)
|
||||
{
|
||||
status = CtorCode_t::Failed();
|
||||
T returnValue = T(AuReference(status), AuForward<T>(args)...);
|
||||
T returnValue = T(AuReference(status), AuForward<Args>(args)...);
|
||||
if (!status)
|
||||
{
|
||||
return AuMove(def);
|
||||
@ -61,7 +61,7 @@ inline T AuTryConstructWithDefault(CtorCode_t &status, T &&def, Args&& ... args)
|
||||
else if constexpr (AuIsConstructible_v<T, Args ..., CtorCode_t &>)
|
||||
{
|
||||
status = CtorCode_t::Failed();
|
||||
T returnValue = T(AuForward<T>(args)..., AuReference(status));
|
||||
T returnValue = T(AuForward<Args>(args)..., AuReference(status));
|
||||
if (!status)
|
||||
{
|
||||
return AuMove(def);
|
||||
@ -73,7 +73,7 @@ inline T AuTryConstructWithDefault(CtorCode_t &status, T &&def, Args&& ... args)
|
||||
try
|
||||
{
|
||||
status = CtorCode_t::Success();
|
||||
return T(AuForward<T>(args)...);
|
||||
return T(AuForward<Args>(args)...);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <auROXTL/auCopyMoveUtils.hpp>
|
||||
#include <auROXTL/auSwapExchangeUtils.hpp>
|
||||
#include <auROXTL/auContainerUtils.hpp>
|
||||
#include <auROXTL/auListUtils.hpp>
|
||||
#include <auROXTL/auStringUtils.hpp>
|
||||
#include <auROXTL/auTupleUtils.hpp>
|
||||
#include <auROXTL/auNumberUtils.hpp>
|
||||
|
Loading…
Reference in New Issue
Block a user