From a9ed64e60011c53786f611f11028d8a9f7ff0048 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Sun, 30 May 2021 03:46:04 +0200 Subject: [PATCH] feat(Core/Util): AsUnderlyingType (#6117) * Add AsUnderlyingType function to cast enum value to its underlying type (avoids repeating std::underlying_type everywhere) (cherry picked from commit https://github.com/TrinityCore/TrinityCore/commit/fdd9227b232db9aae9bc4b2c60ca4de2cdaa0b54) Co-Authored-By: Shauren --- src/common/Utilities/Util.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index 79e7c108f..d9c32a497 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -892,4 +892,11 @@ private: EventStore _eventMap; }; +template +typename std::underlying_type::type AsUnderlyingType(E enumValue) +{ + static_assert(std::is_enum::value, "AsUnderlyingType can only be used with enums"); + return static_cast::type>(enumValue); +} + #endif