From 4f619de6755df5a58f5170f1ad9336b3636de8e0 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 13 May 2020 23:48:28 -0400 Subject: [PATCH] Permits ::get from a reflective enum to an int. --- Reflection/Struct.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Reflection/Struct.cpp b/Reflection/Struct.cpp index 0c175c431..2a2d80736 100644 --- a/Reflection/Struct.cpp +++ b/Reflection/Struct.cpp @@ -11,6 +11,7 @@ #include #include #include +#include // MARK: - Setters @@ -113,11 +114,20 @@ template bool Reflection::get(const Struct &target, const std::s const auto target_type = target.type_of(name); if(!target_type) return false; + // If type is a direct match, copy. if(*target_type == typeid(Type)) { memcpy(&value, target.get(name), sizeof(Type)); return true; } + // If the type is a registered enum and the value type is int, copy. + if constexpr (std::is_integral::value && sizeof(Type) == sizeof(int)) { + if(!Enum::name(*target_type).empty()) { + memcpy(&value, target.get(name), sizeof(int)); + return true; + } + } + return false; }