From b63e55323bd1afa32ee8f2f7b6d9a4e8f588eaf1 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 6 Mar 2026 00:51:07 +0100 Subject: [PATCH] Core/Utils: Modernize Types and Tuples utils - use constexpr variables instead of structs * Also remove unneccessary tuple type list wrapping in packet utilities --- src/common/Time/Timezone.cpp | 3 +- src/common/Utilities/Tuples.h | 42 ++++++------ src/common/Utilities/Types.h | 64 ++++++++++--------- src/server/game/Grids/Dynamic/TypeContainer.h | 4 +- .../game/Server/Packets/PacketUtilities.cpp | 15 +++-- .../game/Server/Packets/PacketUtilities.h | 32 ++++------ 6 files changed, 76 insertions(+), 84 deletions(-) diff --git a/src/common/Time/Timezone.cpp b/src/common/Time/Timezone.cpp index 3dfb99d5f8..584ca59f0e 100644 --- a/src/common/Time/Timezone.cpp +++ b/src/common/Time/Timezone.cpp @@ -18,7 +18,6 @@ #include "Timezone.h" #include "Hash.h" #include "MapUtils.h" -#include "Tuples.h" #include #include #include @@ -170,7 +169,7 @@ std::string GetSystemZoneName() std::string_view FindClosestClientSupportedTimezone(std::string_view currentTimezone, Minutes currentTimezoneOffset) { // try exact match - auto itr = std::ranges::find(_clientSupportedTimezones, currentTimezone, Trinity::TupleElement<1>); + auto itr = std::ranges::find(_clientSupportedTimezones, currentTimezone, Trinity::Containers::MapValue); if (itr != _clientSupportedTimezones.end()) return itr->second; diff --git a/src/common/Utilities/Tuples.h b/src/common/Utilities/Tuples.h index e1c8142166..333b5ec932 100644 --- a/src/common/Utilities/Tuples.h +++ b/src/common/Utilities/Tuples.h @@ -15,48 +15,42 @@ * with this program. If not, see . */ -#ifndef Tuples_h__ -#define Tuples_h__ +#ifndef TRINITYCORE_TUPLES_H +#define TRINITYCORE_TUPLES_H #include namespace Trinity { - template - struct has_type; + template + constexpr bool is_tuple_v = false; + + template + constexpr bool is_tuple_v> = true; + + template + using is_tuple_t = std::bool_constant>; template - struct has_type> : std::disjunction...> - { - }; + constexpr bool tuple_has_type_v = false; template - constexpr bool has_type_v = has_type::value; + constexpr bool tuple_has_type_v> = std::disjunction_v...>; - template - struct is_tuple : std::false_type - { - }; - - template - struct is_tuple> : std::true_type - { - }; - - template - constexpr bool is_tuple_v = is_tuple::value; + template + using tuple_has_type_t = std::bool_constant>; namespace Impl { template - T* new_from_tuple(Tuple&& args, std::index_sequence) + inline T* new_from_tuple(Tuple&& args, std::index_sequence) { return new T(std::get(std::forward(args))...); } } - template - [[nodiscard]] T* new_from_tuple(Tuple&& args) + template + [[nodiscard]] inline T* new_from_tuple(Tuple&& args) { return Impl::new_from_tuple(std::forward(args), std::make_index_sequence>>{}); } @@ -65,4 +59,4 @@ namespace Trinity inline constexpr auto TupleElement = [](Tuple&& tuple) constexpr -> decltype(auto) { return std::get(std::forward(tuple)); }; } -#endif // Tuples_h__ +#endif // TRINITYCORE_TUPLES_H diff --git a/src/common/Utilities/Types.h b/src/common/Utilities/Types.h index 922be079de..5e66eeceb4 100644 --- a/src/common/Utilities/Types.h +++ b/src/common/Utilities/Types.h @@ -15,54 +15,56 @@ * with this program. If not, see . */ -#ifndef Types_h__ -#define Types_h__ +#ifndef TRINITYCORE_TYPES_H +#define TRINITYCORE_TYPES_H #include namespace Trinity { - // end "iterator" tag for find_type_if - struct find_type_end; - - template typename Check, typename... Ts> - struct find_type_if; - - template typename Check> - struct find_type_if + template + struct find_type_result { - using type = find_type_end; + static constexpr bool has_type = HasType; + using type = T; }; - template typename Check, typename T1, typename... Ts> - struct find_type_if : std::conditional_t::value, std::type_identity, find_type_if> + template + struct find_type_result { + static constexpr bool has_type = false; }; + namespace Impl + { + template