|
7 | 7 | #include <meta> |
8 | 8 | #include <atomic> |
9 | 9 |
|
10 | | - |
11 | 10 | #include <rsl/serialize> |
12 | 11 | #include <rsl/repr> |
| 12 | +#include <rsl/kwargs> |
13 | 13 |
|
14 | 14 | namespace rsl::logging { |
15 | 15 | class Field { |
@@ -51,7 +51,7 @@ class Field { |
51 | 51 | auto const& control_block = *static_cast<RefCounted const*>(field->ptr); |
52 | 52 | // control_block.references++; |
53 | 53 | auto val = control_block.references.fetch_add(1); |
54 | | - return Field(field->ptr, field->vtable, field->name); |
| 54 | + return {field->ptr, field->vtable, field->name}; |
55 | 55 | } |
56 | 56 |
|
57 | 57 | static void destroy(void* p) { |
@@ -86,7 +86,7 @@ class Field { |
86 | 86 | return &table; |
87 | 87 | } |
88 | 88 |
|
89 | | - void* ptr = nullptr; |
| 89 | + void* ptr = nullptr; |
90 | 90 | VTable const* vtable = nullptr; |
91 | 91 |
|
92 | 92 | void destroy() { |
@@ -117,10 +117,7 @@ class Field { |
117 | 117 | Field(const Field& other) : Field(copy_from(other)) {} |
118 | 118 |
|
119 | 119 | // move constructor |
120 | | - Field(Field&& other) noexcept |
121 | | - : ptr(other.ptr) |
122 | | - , vtable(other.vtable) |
123 | | - , name(other.name) { |
| 120 | + Field(Field&& other) noexcept : ptr(other.ptr), vtable(other.vtable), name(other.name) { |
124 | 121 | other.ptr = nullptr; |
125 | 122 | other.vtable = nullptr; |
126 | 123 | } |
@@ -148,7 +145,7 @@ class Field { |
148 | 145 | template <typename T> |
149 | 146 | requires(not std::same_as<T, void>) |
150 | 147 | Field(std::string_view name, T* value) |
151 | | - : ptr(value) |
| 148 | + : ptr((void*)value) |
152 | 149 | , vtable(make_vtable<T, false>()) |
153 | 150 | , name(name) {} |
154 | 151 |
|
@@ -191,22 +188,26 @@ class Field { |
191 | 188 | }; |
192 | 189 |
|
193 | 190 | struct ExtraFields { |
194 | | - //TODO this could be a span that views memory on the stack and transitions to heap if its elts do |
| 191 | + // TODO this could be a span that views memory on the stack and transitions to heap if its elts do |
195 | 192 | std::vector<Field> fields; |
196 | 193 |
|
197 | 194 | ExtraFields() = default; |
| 195 | + |
| 196 | + template <std::size_t N> |
| 197 | + explicit(false) ExtraFields(std::array<Field, N> const& fields) {} |
| 198 | + |
198 | 199 | explicit(false) ExtraFields(std::vector<Field> fields) : fields(std::move(fields)) {} |
199 | 200 | template <typename T> |
200 | | - requires std::is_aggregate_v<std::remove_cvref_t<T>> |
201 | | - explicit(false) ExtraFields(T&& kwargs) { |
| 201 | + requires is_kwargs<T> |
| 202 | + explicit(false) ExtraFields(T const& kwargs) { |
202 | 203 | template for (constexpr auto member : std::define_static_array( |
203 | 204 | nonstatic_data_members_of(^^typename std::remove_cvref_t<T>::type, |
204 | 205 | std::meta::access_context::current()))) { |
205 | 206 | static constexpr auto name = std::define_static_string(identifier_of(member)); |
206 | 207 | // we need to clone here |
207 | 208 | // the kwargs wrapper will not live long enough, it'll be destroyed |
208 | 209 | // after the full expression in which this container is created |
209 | | - fields.push_back(Field(name, &kwargs.[:member:]).clone()); |
| 210 | + fields.push_back(Field(name, &kwargs.[:member:])); |
210 | 211 | } |
211 | 212 | } |
212 | 213 |
|
|
0 commit comments