diff --git a/3rdparty/include/meojson/json.hpp b/3rdparty/include/meojson/json.hpp index 571d57596..a1f2ee1a1 100644 --- a/3rdparty/include/meojson/json.hpp +++ b/3rdparty/include/meojson/json.hpp @@ -2577,6 +2577,10 @@ namespace _serialization_helper using char_t = typename string_t::value_type; using ostringstream_t = std::basic_ostringstream, std::allocator>; + template + static constexpr bool is_convertible = + std::is_constructible_v || (loose && has_output_operator::value); + template string_t operator()(input_t&& arg) const { @@ -2596,7 +2600,21 @@ namespace _serialization_helper } } }; -} + + template + void unable_to_serialize() + { + static_assert(!sizeof(T), "Unable to serialize T. " + "You can define the conversion of T to json, or overload operator<< for it. " + "See T below: " +#ifdef _MSC_VER + __FUNCSIG__ +#else + __PRETTY_FUNCTION__ +#endif + ); + } +} // namespace _serialization_helper template MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& string_converter) @@ -2612,12 +2630,16 @@ MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& else if constexpr (std::is_constructible_v, any_t>) { return basic_object(std::forward(arg)); } + else if constexpr (std::decay_t::template is_convertible) { + return string_converter(std::forward(arg)); + } else if constexpr (is_sequence_container>) { basic_value result; for (auto&& val : arg) { using value_t = decltype(val); - result.emplace(serialize(std::forward(val), string_converter)); + result.emplace(serialize(std::forward(val), + std::forward(string_converter))); } return result; } @@ -2628,12 +2650,13 @@ MEOJSON_INLINE basic_value serialize(any_t&& arg, string_converter_t&& using value_t = decltype(val); result.emplace(string_converter(std::forward(key)), - serialize(std::forward(val), string_converter)); + serialize(std::forward(val), + std::forward(string_converter))); } return result; } else { - return string_converter(std::forward(arg)); + unable_to_serialize(); } } diff --git a/source/include/Utils/Logger.h b/source/include/Utils/Logger.h index 91c4b2dac..b53285904 100644 --- a/source/include/Utils/Logger.h +++ b/source/include/Utils/Logger.h @@ -101,6 +101,11 @@ class MAA_UTILS_API Logger private: struct string_converter { + template + static constexpr bool is_convertible = + std::same_as> || std::same_as> || + has_output_operator; + template std::string operator()(T&& value) const {