From f3fcfebfe66cf1806a939810cfba8408d727b437 Mon Sep 17 00:00:00 2001 From: MistEO Date: Thu, 19 Oct 2023 19:51:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20serialize=20?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E6=A8=A1=E6=9D=BF=E6=8E=A8?= =?UTF-8?q?=E5=AF=BC=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/json.hpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/include/json.hpp b/include/json.hpp index 41546ae..a3e3505 100644 --- a/include/json.hpp +++ b/include/json.hpp @@ -2528,11 +2528,13 @@ MEOJSON_INLINE const basic_value invalid_value() namespace _serialization_helper { - template + template class has_output_operator { + using ostringstream_t = std::basic_ostringstream, std::allocator>; + template - static auto test(int) -> decltype(std::declval() << std::declval(), std::true_type()); + static auto test(int) -> decltype(std::declval() << std::declval(), std::true_type()); template static std::false_type test(...); @@ -2566,17 +2568,12 @@ namespace _serialization_helper template MEOJSON_INLINE string_t to_stream_string(input_t&& arg) { - if constexpr (has_output_operator::value) { - using char_t = typename string_t::value_type; - using stringstream_t = std::basic_stringstream, std::allocator>; + using char_t = typename string_t::value_type; + using ostringstream_t = std::basic_ostringstream, std::allocator>; - stringstream_t ss; - ss << std::forward(arg); - return std::move(ss).str(); - } - else { - static_assert(!sizeof(input_t), "Unable to convert type to string, there is no operator <<."); - } + ostringstream_t os; + os << std::forward(arg); + return std::move(os).str(); } template