Browse Source

chore: update magic_enum => 0.9.5

Sam Jaffe 2 years ago
parent
commit
c31bde4e3d
2 changed files with 14 additions and 10 deletions
  1. 6 6
      include/serializer/jsonizer.tpp
  2. 8 4
      include/serializer/strconv.h

+ 6 - 6
include/serializer/jsonizer.tpp

@@ -11,7 +11,7 @@
 
 #include <expect/expect.hpp>
 #include <json/json.h>
-#include <magic_enum.hpp>
+#include <magic_enum/magic_enum.hpp>
 #include <string_utils/cast.h>
 
 #include <serializer/jsonizer.h>
@@ -40,7 +40,8 @@ Json::Value Jsonizer::to_json(T & value, std::index_sequence<Is...>) const {
   return json;
 }
 
-template <typename T> Json::Value Jsonizer::to_json(std::optional<T> const &opt) const {
+template <typename T>
+Json::Value Jsonizer::to_json(std::optional<T> const & opt) const {
   return opt.has_value() ? to_json(*opt) : Json::Value();
 }
 
@@ -48,9 +49,7 @@ template <typename T> Json::Value Jsonizer::to_json(T const & value) const {
   if constexpr (detail::has_serial_type_v<T>) {
     return to_json(static_cast<typename T::serial_type>(value));
   } else if constexpr (std::is_enum_v<T>) {
-    constexpr auto type =
-        magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
-    return std::string(magic_enum::enum_name<type>(value));
+    return to_string(value);
   } else if constexpr (detail::is_tuple_v<T>) {
     return to_json(value, std::make_index_sequence<std::tuple_size_v<T>>());
   } else if constexpr (std::is_constructible_v<std::string, T>) {
@@ -97,7 +96,8 @@ void Jsonizer::from_json(T & value, Json::Value const & json,
 }
 
 template <typename T>
-void Jsonizer::from_json(std::optional<T> &opt, Json::Value const & json) const {
+void Jsonizer::from_json(std::optional<T> & opt,
+                         Json::Value const & json) const {
   opt = json.isNull() ? std::nullopt : std::optional{from_json<T>(json)};
 }
 

+ 8 - 4
include/serializer/strconv.h

@@ -11,7 +11,8 @@
 #include <string_view>
 #include <type_traits>
 
-#include <magic_enum.hpp>
+#include <magic_enum/magic_enum.hpp>
+#include <magic_enum/magic_enum_flags.hpp>
 
 #include <serializer/traits.h>
 
@@ -26,9 +27,12 @@ template <typename T> std::string to_string(T const & elem) {
     using ::serializer::to_string;
     return elem ? to_string(*elem) : "nil";
   } else if constexpr (std::is_enum_v<T>) {
-    constexpr auto type =
-        magic_enum::as_flags<magic_enum::detail::is_flags_v<T>>;
-    return std::string(magic_enum::enum_name<type>(elem));
+    if constexpr (magic_enum::detail::subtype_v<T> ==
+                  magic_enum::detail::enum_subtype::flags) {
+      return std::string(magic_enum::enum_flags_name<T>(elem));
+    } else {
+      return std::string(magic_enum::enum_name<T>(elem));
+    }
   } else {
     static_assert(detail::always_false<T>{});
   }