From a49dd60755e48d7c8ebaf22f06177235e22b45b2 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 17 Jan 2025 18:38:46 +0100 Subject: Core/Misc: Remove return type std::enable_if based SFINAE --- src/common/Cryptography/BigNumber.h | 14 ++++--- src/common/Cryptography/CryptoHash.h | 4 +- src/common/Cryptography/HMAC.h | 4 +- src/common/Utilities/EventProcessor.h | 23 +++++----- src/server/game/DataStores/DB2HotfixGenerator.h | 17 +++----- src/server/game/Entities/Object/ObjectGuid.h | 56 ++++++++++++------------- 6 files changed, 57 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/common/Cryptography/BigNumber.h b/src/common/Cryptography/BigNumber.h index 3815339d9cf..b18eda340a0 100644 --- a/src/common/Cryptography/BigNumber.h +++ b/src/common/Cryptography/BigNumber.h @@ -20,12 +20,17 @@ #include "Define.h" #include +#include #include #include #include struct bignum_st; +template +concept BigNumberBinaryInput = std::ranges::contiguous_range + && std::same_as, uint8>; + class TC_COMMON_API BigNumber { public: @@ -34,9 +39,8 @@ class TC_COMMON_API BigNumber BigNumber(uint32 v) : BigNumber() { SetDword(v); } BigNumber(int32 v) : BigNumber() { SetDword(v); } BigNumber(std::string const& v) : BigNumber() { SetHexStr(v); } - BigNumber(std::vector const& v, bool littleEndian = true) : BigNumber() { SetBinary(v.data(), v.size(), littleEndian); } - template - BigNumber(std::array const& v, bool littleEndian = true) : BigNumber() { SetBinary(v.data(), Size, littleEndian); } + template + BigNumber(Container const& binary, bool littleEndian = true) : BigNumber() { SetBinary(std::ranges::data(binary), std::ranges::size(binary), littleEndian); } ~BigNumber(); @@ -44,8 +48,8 @@ class TC_COMMON_API BigNumber void SetDword(uint32); void SetQword(uint64); void SetBinary(uint8 const* bytes, int32 len, bool littleEndian = true); - template - auto SetBinary(Container const& c, bool littleEndian = true) -> std::enable_if_t>> { SetBinary(std::data(c), std::size(c), littleEndian); } + template + void SetBinary(Container const& binary, bool littleEndian = true) { SetBinary(std::ranges::data(binary), std::ranges::size(binary), littleEndian); } bool SetDecStr(char const* str); bool SetDecStr(std::string const& str) { return SetDecStr(str.c_str()); } bool SetHexStr(char const* str); diff --git a/src/common/Cryptography/CryptoHash.h b/src/common/Cryptography/CryptoHash.h index 34b299c1d4f..060dbcd0f4f 100644 --- a/src/common/Cryptography/CryptoHash.h +++ b/src/common/Cryptography/CryptoHash.h @@ -54,8 +54,8 @@ namespace Trinity::Impl return hash.GetDigest(); } - template - static auto GetDigestOf(Ts&&... pack) -> std::enable_if_t>...>, Digest> + template >...>, int32> = 0> + static Digest GetDigestOf(Ts&&... pack) { GenericHash hash; (hash.UpdateData(std::forward(pack)), ...); diff --git a/src/common/Cryptography/HMAC.h b/src/common/Cryptography/HMAC.h index c4af92606ae..9668da31819 100644 --- a/src/common/Cryptography/HMAC.h +++ b/src/common/Cryptography/HMAC.h @@ -46,8 +46,8 @@ namespace Trinity::Impl return hash.GetDigest(); } - template - static auto GetDigestOf(Container const& seed, Ts&&... pack) -> std::enable_if_t>...>, Digest> + template >...>, int32> = 0> + static Digest GetDigestOf(Container const& seed, Ts&&... pack) { GenericHMAC hash(seed); (hash.UpdateData(std::forward(pack)), ...); diff --git a/src/common/Utilities/EventProcessor.h b/src/common/Utilities/EventProcessor.h index 7f662e473ca..9c6e50b83da 100644 --- a/src/common/Utilities/EventProcessor.h +++ b/src/common/Utilities/EventProcessor.h @@ -21,6 +21,7 @@ #include "Define.h" #include "Duration.h" #include "Random.h" +#include #include #include @@ -74,7 +75,7 @@ template class LambdaBasicEvent : public BasicEvent { public: - LambdaBasicEvent(T&& callback) : BasicEvent(), _callback(std::move(callback)) { } + explicit LambdaBasicEvent(T&& callback) : BasicEvent(), _callback(std::move(callback)) { } bool Execute(uint64, uint32) override { @@ -83,31 +84,31 @@ public: } private: - T _callback; }; -template -using is_lambda_event = std::enable_if_t>>>; - class TC_COMMON_API EventProcessor { public: EventProcessor() : m_time(0) { } + EventProcessor(EventProcessor const&) = delete; + EventProcessor(EventProcessor&&) = delete; + EventProcessor& operator=(EventProcessor const&) = delete; + EventProcessor& operator=(EventProcessor&&) = delete; ~EventProcessor(); void Update(uint32 p_time); void KillAllEvents(bool force); void AddEvent(BasicEvent* event, Milliseconds e_time, bool set_addtime = true); - template - is_lambda_event AddEvent(T&& event, Milliseconds e_time, bool set_addtime = true) { AddEvent(new LambdaBasicEvent(std::move(event)), e_time, set_addtime); } + template T> + void AddEvent(T&& event, Milliseconds e_time, bool set_addtime = true) { AddEvent(new LambdaBasicEvent(std::forward(event)), e_time, set_addtime); } void AddEventAtOffset(BasicEvent* event, Milliseconds offset) { AddEvent(event, CalculateTime(offset)); } void AddEventAtOffset(BasicEvent* event, Milliseconds offset, Milliseconds offset2) { AddEvent(event, CalculateTime(randtime(offset, offset2))); } - template - is_lambda_event AddEventAtOffset(T&& event, Milliseconds offset) { AddEventAtOffset(new LambdaBasicEvent(std::move(event)), offset); } - template - is_lambda_event AddEventAtOffset(T&& event, Milliseconds offset, Milliseconds offset2) { AddEventAtOffset(new LambdaBasicEvent(std::move(event)), offset, offset2); } + template T> + void AddEventAtOffset(T&& event, Milliseconds offset) { AddEventAtOffset(new LambdaBasicEvent(std::forward(event)), offset); } + template T> + void AddEventAtOffset(T&& event, Milliseconds offset, Milliseconds offset2) { AddEventAtOffset(new LambdaBasicEvent(std::forward(event)), offset, offset2); } void ModifyEventTime(BasicEvent* event, Milliseconds newTime); Milliseconds CalculateTime(Milliseconds t_offset) const { return Milliseconds(m_time) + t_offset; } std::multimap const& GetEvents() const { return m_events; } diff --git a/src/server/game/DataStores/DB2HotfixGenerator.h b/src/server/game/DataStores/DB2HotfixGenerator.h index cd7c48c66bc..6287160dbe3 100644 --- a/src/server/game/DataStores/DB2HotfixGenerator.h +++ b/src/server/game/DataStores/DB2HotfixGenerator.h @@ -19,7 +19,7 @@ #define DB2HotfixGenerator_h__ #include "DB2Store.h" -#include +#include class TC_GAME_API DB2HotfixGeneratorBase { @@ -34,24 +34,18 @@ class DB2HotfixGenerator : private DB2HotfixGeneratorBase public: explicit DB2HotfixGenerator(DB2Storage& storage) : _storage(storage), _count(0) { } - void ApplyHotfix(uint32 id, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix({ id }, fixer, notifyClient); } - void ApplyHotfix(std::initializer_list ids, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix(ids.begin(), ids.end(), fixer, notifyClient); } - - template()))>::value>::type> - void ApplyHotfix(I const& ids, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix(std::begin(ids), std::end(ids), fixer, notifyClient); } + void ApplyHotfix(uint32 id, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix({ &id, 1 }, fixer, notifyClient); } uint32 GetAppliedHotfixesCount() const { return _count; } -private: - void ApplyHotfix(uint32 const* begin, uint32 const* end, void(*fixer)(T*), bool notifyClient) + void ApplyHotfix(std::span ids, void(*fixer)(T*), bool notifyClient) { - while (begin != end) + for (uint32 id : ids) { - uint32 id = *begin++; T const* entry = _storage.LookupEntry(id); if (!entry) { - DB2HotfixGeneratorBase::LogMissingRecord(_storage.GetFileName().c_str(), id); + DB2HotfixGeneratorBase::LogMissingRecord(_storage.GetFileName(), id); continue; } @@ -63,6 +57,7 @@ private: } } +private: DB2Storage& _storage; uint32 _count; }; diff --git a/src/server/game/Entities/Object/ObjectGuid.h b/src/server/game/Entities/Object/ObjectGuid.h index 337c2d808bd..647045aa59e 100644 --- a/src/server/game/Entities/Object/ObjectGuid.h +++ b/src/server/game/Entities/Object/ObjectGuid.h @@ -359,26 +359,26 @@ class TC_GAME_API ObjectGuid static ObjectGuid FromString(std::string_view guidString); std::size_t GetHash() const; - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Null, ObjectGuid> Create() { return ObjectGuidFactory::CreateNull(); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Uniq, ObjectGuid> Create(ObjectGuid::LowType id) { return ObjectGuidFactory::CreateUniq(id); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Player, ObjectGuid> Create(ObjectGuid::LowType dbId) { return ObjectGuidFactory::CreatePlayer(0, dbId); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Item, ObjectGuid> Create(ObjectGuid::LowType dbId) { return ObjectGuidFactory::CreateItem(0, dbId); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::WorldObject, ObjectGuid> Create(uint16 mapId, uint32 entry, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateWorldObject(type, 0, 0, mapId, 0, entry, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::WorldObject, ObjectGuid> Create(uint8 subType, uint16 mapId, uint32 entry, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateWorldObject(type, subType, 0, mapId, 0, entry, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Transport, ObjectGuid> Create(uint32 counter) { return ObjectGuidFactory::CreateTransport(type, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::ClientActor, ObjectGuid> Create(uint16 ownerType, uint16 ownerId, uint32 counter) { return ObjectGuidFactory::CreateClientActor(ownerType, ownerId, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::ChatChannel, ObjectGuid> Create(bool builtIn, bool trade, uint16 zoneId, uint8 factionGroupMask, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateChatChannel(0, builtIn, trade, zoneId, factionGroupMask, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Global, ObjectGuid> Create(ObjectGuid::LowType dbId) { return ObjectGuidFactory::CreateGlobal(type, UI64LIT(0), dbId); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Guild, ObjectGuid> Create(ObjectGuid::LowType dbId) { return ObjectGuidFactory::CreateGuild(type, 0, dbId); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::MobileSession, ObjectGuid> Create(uint16 arg1, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateMobileSession(0, arg1, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::WebObj, ObjectGuid> Create(uint8 arg1, uint8 arg2, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateWebObj(0, arg1, arg2, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::LFGObject, ObjectGuid> Create(uint8 arg1, uint8 arg2, uint8 arg3, uint8 arg4, bool arg5, uint8 arg6, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateLFGObject(arg1, arg2, arg3, arg4, arg5, arg6, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::LFGList, ObjectGuid> Create(uint8 arg1, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateLFGList(arg1, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::Client, ObjectGuid> Create(uint32 arg1, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateClient(type, 0, arg1, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::ClubFinder, ObjectGuid> Create(uint8 clubType, uint32 clubFinderId, ObjectGuid::LowType dbId) { return ObjectGuidFactory::CreateClubFinder(0, clubType, clubFinderId, dbId); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::ToolsClient, ObjectGuid> Create(uint16 mapId, uint32 serverId, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateToolsClient(mapId, serverId, counter); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::WorldLayer, ObjectGuid> Create(uint32 arg1, uint16 arg2, uint8 arg3, uint32 arg4) { return ObjectGuidFactory::CreateWorldLayer(arg1, arg2, arg3, arg4); } - template static std::enable_if_t::Format::value == ObjectGuidFormatType::LMMLobby, ObjectGuid> Create(uint32 arg2, uint8 arg3, uint8 arg4, ObjectGuid::LowType counter) { return ObjectGuidFactory::CreateLMMLobby(0, arg2, arg3, arg4, counter); } + template ::Format::value == ObjectGuidFormatType::Null, int32> = 0> static ObjectGuid Create() { return ObjectGuidFactory::CreateNull(); } + template ::Format::value == ObjectGuidFormatType::Uniq, int32> = 0> static ObjectGuid Create(LowType id) { return ObjectGuidFactory::CreateUniq(id); } + template ::Format::value == ObjectGuidFormatType::Player, int32> = 0> static ObjectGuid Create(LowType dbId) { return ObjectGuidFactory::CreatePlayer(0, dbId); } + template ::Format::value == ObjectGuidFormatType::Item, int32> = 0> static ObjectGuid Create(LowType dbId) { return ObjectGuidFactory::CreateItem(0, dbId); } + template ::Format::value == ObjectGuidFormatType::WorldObject, int32> = 0> static ObjectGuid Create(uint16 mapId, uint32 entry, LowType counter) { return ObjectGuidFactory::CreateWorldObject(type, 0, 0, mapId, 0, entry, counter); } + template ::Format::value == ObjectGuidFormatType::WorldObject, int32> = 0> static ObjectGuid Create(uint8 subType, uint16 mapId, uint32 entry, LowType counter) { return ObjectGuidFactory::CreateWorldObject(type, subType, 0, mapId, 0, entry, counter); } + template ::Format::value == ObjectGuidFormatType::Transport, int32> = 0> static ObjectGuid Create(uint32 counter) { return ObjectGuidFactory::CreateTransport(type, counter); } + template ::Format::value == ObjectGuidFormatType::ClientActor, int32> = 0> static ObjectGuid Create(uint16 ownerType, uint16 ownerId, uint32 counter) { return ObjectGuidFactory::CreateClientActor(ownerType, ownerId, counter); } + template ::Format::value == ObjectGuidFormatType::ChatChannel, int32> = 0> static ObjectGuid Create(bool builtIn, bool trade, uint16 zoneId, uint8 factionGroupMask, LowType counter) { return ObjectGuidFactory::CreateChatChannel(0, builtIn, trade, zoneId, factionGroupMask, counter); } + template ::Format::value == ObjectGuidFormatType::Global, int32> = 0> static ObjectGuid Create(LowType dbId) { return ObjectGuidFactory::CreateGlobal(type, UI64LIT(0), dbId); } + template ::Format::value == ObjectGuidFormatType::Guild, int32> = 0> static ObjectGuid Create(LowType dbId) { return ObjectGuidFactory::CreateGuild(type, 0, dbId); } + template ::Format::value == ObjectGuidFormatType::MobileSession, int32> = 0> static ObjectGuid Create(uint16 arg1, LowType counter) { return ObjectGuidFactory::CreateMobileSession(0, arg1, counter); } + template ::Format::value == ObjectGuidFormatType::WebObj, int32> = 0> static ObjectGuid Create(uint8 arg1, uint8 arg2, LowType counter) { return ObjectGuidFactory::CreateWebObj(0, arg1, arg2, counter); } + template ::Format::value == ObjectGuidFormatType::LFGObject, int32> = 0> static ObjectGuid Create(uint8 arg1, uint8 arg2, uint8 arg3, uint8 arg4, bool arg5, uint8 arg6, LowType counter) { return ObjectGuidFactory::CreateLFGObject(arg1, arg2, arg3, arg4, arg5, arg6, counter); } + template ::Format::value == ObjectGuidFormatType::LFGList, int32> = 0> static ObjectGuid Create(uint8 arg1, LowType counter) { return ObjectGuidFactory::CreateLFGList(arg1, counter); } + template ::Format::value == ObjectGuidFormatType::Client, int32> = 0> static ObjectGuid Create(uint32 arg1, LowType counter) { return ObjectGuidFactory::CreateClient(type, 0, arg1, counter); } + template ::Format::value == ObjectGuidFormatType::ClubFinder, int32> = 0> static ObjectGuid Create(uint8 clubType, uint32 clubFinderId, LowType dbId) { return ObjectGuidFactory::CreateClubFinder(0, clubType, clubFinderId, dbId); } + template ::Format::value == ObjectGuidFormatType::ToolsClient, int32> = 0> static ObjectGuid Create(uint16 mapId, uint32 serverId, LowType counter) { return ObjectGuidFactory::CreateToolsClient(mapId, serverId, counter); } + template ::Format::value == ObjectGuidFormatType::WorldLayer, int32> = 0> static ObjectGuid Create(uint32 arg1, uint16 arg2, uint8 arg3, uint32 arg4) { return ObjectGuidFactory::CreateWorldLayer(arg1, arg2, arg3, arg4); } + template ::Format::value == ObjectGuidFormatType::LMMLobby, int32> = 0> static ObjectGuid Create(uint32 arg2, uint8 arg3, uint8 arg4, LowType counter) { return ObjectGuidFactory::CreateLMMLobby(0, arg2, arg3, arg4, counter); } protected: ObjectGuid(uint64 high, uint64 low) : _data({{ low, high }}) @@ -414,18 +414,14 @@ protected: TC_GAME_API ByteBuffer& operator<<(ByteBuffer& buf, ObjectGuid const& guid); TC_GAME_API ByteBuffer& operator>>(ByteBuffer& buf, ObjectGuid& guid); -namespace std +template<> +struct std::hash { - template<> - struct hash + size_t operator()(ObjectGuid const& key) const noexcept { - public: - size_t operator()(ObjectGuid const& key) const noexcept - { - return key.GetHash(); - } - }; -} + return key.GetHash(); + } +}; namespace fmt { -- cgit v1.2.3