aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2025-01-17 18:38:46 +0100
committerShauren <shauren.trinity@gmail.com>2025-01-17 18:38:46 +0100
commita43beb3e063421957b8b99095bb1a3e44268662c (patch)
tree3a404f6acf06f3a250d54038399c2cd0c40a304f /src/common
parent5ea4b26f7a32880834419fc3997f8b7908d30508 (diff)
Core/Misc: Remove return type std::enable_if based SFINAE
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Cryptography/BigNumber.h14
-rw-r--r--src/common/Cryptography/CryptoHash.h4
-rw-r--r--src/common/Cryptography/HMAC.h4
-rw-r--r--src/common/Utilities/EventProcessor.h23
4 files changed, 25 insertions, 20 deletions
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 <array>
+#include <concepts>
#include <memory>
#include <string>
#include <vector>
struct bignum_st;
+template <typename Container>
+concept BigNumberBinaryInput = std::ranges::contiguous_range<Container>
+ && std::same_as<std::ranges::range_value_t<Container>, 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<uint8> const& v, bool littleEndian = true) : BigNumber() { SetBinary(v.data(), v.size(), littleEndian); }
- template <size_t Size>
- BigNumber(std::array<uint8, Size> const& v, bool littleEndian = true) : BigNumber() { SetBinary(v.data(), Size, littleEndian); }
+ template <BigNumberBinaryInput Container>
+ 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 <typename Container>
- auto SetBinary(Container const& c, bool littleEndian = true) -> std::enable_if_t<!std::is_pointer_v<std::decay_t<Container>>> { SetBinary(std::data(c), std::size(c), littleEndian); }
+ template <BigNumberBinaryInput Container>
+ 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 <typename... Ts>
- static auto GetDigestOf(Ts&&... pack) -> std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, Digest>
+ template <typename... Ts, std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, int32> = 0>
+ static Digest GetDigestOf(Ts&&... pack)
{
GenericHash hash;
(hash.UpdateData(std::forward<Ts>(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 <typename Container, typename... Ts>
- static auto GetDigestOf(Container const& seed, Ts&&... pack) -> std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, Digest>
+ template <typename Container, typename... Ts, std::enable_if_t<std::conjunction_v<std::negation<std::is_integral<Ts>>...>, int32> = 0>
+ static Digest GetDigestOf(Container const& seed, Ts&&... pack)
{
GenericHMAC hash(seed);
(hash.UpdateData(std::forward<Ts>(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 <concepts>
#include <map>
#include <type_traits>
@@ -74,7 +75,7 @@ template<typename T>
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<typename T>
-using is_lambda_event = std::enable_if_t<!std::is_base_of_v<BasicEvent, std::remove_pointer_t<std::remove_cvref_t<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<typename T>
- is_lambda_event<T> AddEvent(T&& event, Milliseconds e_time, bool set_addtime = true) { AddEvent(new LambdaBasicEvent<T>(std::move(event)), e_time, set_addtime); }
+ template<std::invocable<> T>
+ void AddEvent(T&& event, Milliseconds e_time, bool set_addtime = true) { AddEvent(new LambdaBasicEvent<T>(std::forward<T>(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<typename T>
- is_lambda_event<T> AddEventAtOffset(T&& event, Milliseconds offset) { AddEventAtOffset(new LambdaBasicEvent<T>(std::move(event)), offset); }
- template<typename T>
- is_lambda_event<T> AddEventAtOffset(T&& event, Milliseconds offset, Milliseconds offset2) { AddEventAtOffset(new LambdaBasicEvent<T>(std::move(event)), offset, offset2); }
+ template<std::invocable<> T>
+ void AddEventAtOffset(T&& event, Milliseconds offset) { AddEventAtOffset(new LambdaBasicEvent<T>(std::forward<T>(event)), offset); }
+ template<std::invocable<> T>
+ void AddEventAtOffset(T&& event, Milliseconds offset, Milliseconds offset2) { AddEventAtOffset(new LambdaBasicEvent<T>(std::forward<T>(event)), offset, offset2); }
void ModifyEventTime(BasicEvent* event, Milliseconds newTime);
Milliseconds CalculateTime(Milliseconds t_offset) const { return Milliseconds(m_time) + t_offset; }
std::multimap<uint64, BasicEvent*> const& GetEvents() const { return m_events; }