@@ -33,14 +33,7 @@ template <typename T>
33
33
std::ostream& operator <<(std::ostream& os, const std::optional<T>& v);
34
34
35
35
template <typename T>
36
- concept has_stream_insertion_operator = requires { std::declval<std::ostream&>() << std::declval<T>(); };
37
- template <typename T>
38
- concept has_value_type = requires { typename std::decay_t <T>::value_type; };
39
- template <typename T>
40
- concept has_key_mapped_type = requires {
41
- typename std::decay_t <T>::key_type;
42
- typename std::decay_t <T>::mapped_type;
43
- };
36
+ concept has_output_operator = requires { std::declval<std::ostream&>() << std::declval<T>(); };
44
37
45
38
class MAA_UTILS_API Logger
46
39
{
@@ -115,7 +108,7 @@ class MAA_UTILS_API Logger
115
108
else if constexpr (std::same_as<std::wstring, std::decay_t <T>>) {
116
109
return from_u16 (std::forward<T>(value));
117
110
}
118
- else if constexpr (has_stream_insertion_operator <T>) {
111
+ else if constexpr (has_output_operator <T>) {
119
112
return std::forward<T>(value);
120
113
}
121
114
else if constexpr (std::is_constructible_v<json::array, T>) {
@@ -124,54 +117,8 @@ class MAA_UTILS_API Logger
124
117
else if constexpr (std::is_constructible_v<json::object, T>) {
125
118
return json::object (std::forward<T>(value));
126
119
}
127
- else if constexpr (MAA_RNS::ranges::input_range<T> && has_value_type<T> && !has_key_mapped_type<T>) {
128
- using value_type = typename std::decay_t <T>::value_type;
129
- using value_stream_type = decltype (to_stream (std::declval<value_type>()));
130
-
131
- json::value jtmp;
132
- for (auto && val : value) {
133
- if constexpr (std::is_constructible_v<json::value, value_stream_type>) {
134
- jtmp.emplace (to_stream (std::forward<decltype (val)>(val)));
135
- }
136
- else {
137
- std::stringstream val_ss;
138
- val_ss << to_stream (std::forward<decltype (val)>(val));
139
- jtmp.emplace (std::move (val_ss).str ());
140
- }
141
- }
142
- return jtmp;
143
- }
144
- else if constexpr (MAA_RNS::ranges::input_range<T> && has_value_type<T> && has_key_mapped_type<T>) {
145
- using key_type = typename std::decay_t <T>::key_type;
146
- using key_stream_type = decltype (to_stream (std::declval<key_type>()));
147
- using mapped_type = typename std::decay_t <T>::mapped_type;
148
- using mapped_stream_type = decltype (to_stream (std::declval<mapped_type>()));
149
-
150
- json::value jtmp;
151
- for (auto && [key, val] : value) {
152
- json::object::key_type strkey;
153
- if constexpr (std::is_constructible_v<json::object::key_type, key_stream_type>) {
154
- strkey = to_stream (key);
155
- }
156
- else {
157
- std::stringstream key_ss;
158
- key_ss << to_stream (key);
159
- strkey = std::move (key_ss).str ();
160
- }
161
-
162
- if constexpr (std::is_constructible_v<json::value, mapped_stream_type>) {
163
- jtmp.emplace (std::move (strkey), to_stream (std::forward<decltype (val)>(val)));
164
- }
165
- else {
166
- std::stringstream val_ss;
167
- val_ss << to_stream (std::forward<decltype (val)>(val));
168
- jtmp.emplace (std::move (strkey), std::move (val_ss).str ());
169
- }
170
- }
171
- return jtmp;
172
- }
173
120
else {
174
- static_assert (! sizeof (T), " Unsupported type " );
121
+ return json::serialize< true >(std::forward<T>(value) );
175
122
}
176
123
}
177
124
0 commit comments