16
16
namespace glz
17
17
{
18
18
namespace detail
19
- {
19
+ {
20
20
template <class T = void >
21
21
struct to_binary {};
22
22
@@ -29,15 +29,15 @@ namespace glz
29
29
return to_binary<std::decay_t <T>>::template op<Opts>(
30
30
std::forward<T>(value), std::forward<B>(b));
31
31
}
32
-
32
+
33
33
template <auto Opts, class T , class B , class IX >
34
34
static auto op (T&& value, B&& b, IX&& ix)
35
35
{
36
36
return to_binary<std::decay_t <T>>::template op<Opts>(
37
37
std::forward<T>(value), std::forward<B>(b), std::forward<IX>(ix));
38
38
}
39
39
};
40
-
40
+
41
41
template <class T >
42
42
requires (std::same_as<T, bool > || std::same_as<T, std::vector<bool >::reference> || std::same_as<T, std::vector<bool >::const_reference>)
43
43
struct to_binary <T> final
@@ -61,13 +61,13 @@ namespace glz
61
61
static auto op (auto && /* value*/ , Args&&... args) noexcept
62
62
{ return error{}; }
63
63
};
64
-
64
+
65
65
template <class ... Args>
66
66
auto dump_type (auto && value, Args&&... args) noexcept
67
67
{
68
68
return dump (std::as_bytes (std::span{ &value, 1 }), std::forward<Args>(args)...);
69
69
}
70
-
70
+
71
71
template <uint64_t i, class ... Args>
72
72
[[nodiscard]] auto dump_int (Args&&... args) noexcept
73
73
{
@@ -92,7 +92,7 @@ namespace glz
92
92
" size not supported" );
93
93
}
94
94
}
95
-
95
+
96
96
template <auto Opts, class ... Args>
97
97
[[nodiscard]] auto dump_int (size_t i, Args&&... args) noexcept (Opts.no_except)
98
98
{
@@ -117,7 +117,7 @@ namespace glz
117
117
}
118
118
}
119
119
}
120
-
120
+
121
121
template <class T >
122
122
requires num_t <T> || char_t <T> || glaze_enum_t <T>
123
123
struct to_binary <T> final
@@ -128,7 +128,7 @@ namespace glz
128
128
return dump_type (value, std::forward<Args>(args)...);
129
129
}
130
130
};
131
-
131
+
132
132
template <str_t T>
133
133
struct to_binary <T> final
134
134
{
@@ -139,7 +139,7 @@ namespace glz
139
139
dump (std::as_bytes (std::span{ value.data (), value.size () }), std::forward<Args>(args)...);
140
140
}
141
141
};
142
-
142
+
143
143
template <array_t T>
144
144
struct to_binary <T> final
145
145
{
@@ -154,7 +154,7 @@ namespace glz
154
154
}
155
155
}
156
156
};
157
-
157
+
158
158
template <map_t T>
159
159
struct to_binary <T> final
160
160
{
@@ -168,7 +168,7 @@ namespace glz
168
168
}
169
169
}
170
170
};
171
-
171
+
172
172
template <nullable_t T>
173
173
struct to_binary <T> final
174
174
{
@@ -184,7 +184,7 @@ namespace glz
184
184
}
185
185
}
186
186
};
187
-
187
+
188
188
template <class T >
189
189
requires glaze_object_t <T>
190
190
struct to_binary <T> final
@@ -195,7 +195,7 @@ namespace glz
195
195
using V = std::decay_t <T>;
196
196
static constexpr auto N = std::tuple_size_v<meta_t <V>>;
197
197
dump_int<N>(std::forward<Args>(args)...); // even though N is known at compile time in this case, it is not known for partial cases, so we still use a compressed integer
198
-
198
+
199
199
for_each<N>([&](auto I) {
200
200
static constexpr auto item = std::get<I>(meta_v<V>);
201
201
dump_int<Opts>(I, std::forward<Args>(args)...); // dump the known key as an integer
@@ -224,19 +224,19 @@ namespace glz
224
224
}
225
225
};
226
226
}
227
-
227
+
228
228
template <class T , class Buffer >
229
229
inline auto write_binary (T&& value, Buffer&& buffer) {
230
230
return write <opts{.format = binary}>(std::forward<T>(value), std::forward<Buffer>(buffer));
231
231
}
232
-
232
+
233
233
template <class T >
234
234
inline auto write_binary (T&& value) {
235
235
std::string buffer{};
236
236
write <opts{.format = binary}>(std::forward<T>(value), buffer);
237
237
return buffer;
238
238
}
239
-
239
+
240
240
template <auto & Partial, opts Opts, class T , class Buffer >
241
241
requires nano::ranges::input_range<Buffer> && (sizeof (nano::ranges::range_value_t <Buffer>) == sizeof (char ))
242
242
inline auto write (T&& value, Buffer& buffer) noexcept
@@ -260,9 +260,11 @@ namespace glz
260
260
if constexpr (detail::glaze_object_t <std::decay_t <T>>) {
261
261
static constexpr auto key_to_int = detail::make_key_int_map<T>();
262
262
glz::for_each<N>([&](auto I) {
263
- static constexpr auto group = []() {
264
- return std::get<decltype (I)::value>(groups);
265
- }(); // MSVC internal compiler error workaround
263
+ using index_t = decltype (I);
264
+ using group_t = std::tuple_element_t <I, decltype (groups)>;
265
+ static constexpr auto group = [](index_t Index) constexpr -> group_t {
266
+ return std::get<Index>(groups);
267
+ }({}); // MSVC internal compiler error workaround
266
268
static constexpr auto key = std::get<0 >(group);
267
269
static constexpr auto sub_partial = std::get<1 >(group);
268
270
static constexpr auto frozen_map = detail::make_map<T>();
@@ -298,12 +300,12 @@ namespace glz
298
300
else {
299
301
throw std::runtime_error (
300
302
" Invalid key for map when writing out partial message" );
301
- }
303
+ }
302
304
});
303
305
}
304
306
}
305
307
}
306
-
308
+
307
309
template <auto & Partial, class T , class Buffer >
308
310
inline auto write_binary (T&& value, Buffer&& buffer) {
309
311
return write <Partial, opts{}>(std::forward<T>(value), std::forward<Buffer>(buffer));
0 commit comments