Skip to content

Commit 7f3fd9f

Browse files
committed
maybe_skipped boolean
1 parent f4cefd0 commit 7f3fd9f

File tree

3 files changed

+21
-36
lines changed

3 files changed

+21
-36
lines changed

include/glaze/core/reflect.hpp

+19-34
Original file line numberDiff line numberDiff line change
@@ -218,44 +218,29 @@ namespace glz
218218
// The decayed type after get_member is called
219219
template <class T, size_t I>
220220
using field_t = std::remove_cvref_t<refl_t<T, I>>;
221-
222-
// MSVC requires this specialization, otherwise it will try to instatiate dead `if constexpr` branches for N == 0
223-
template <opts Opts, class T>
224-
struct object_info;
225-
226-
template <opts Opts, class T>
227-
requires(reflect<T>::size == 0)
228-
struct object_info<Opts, T>
229-
{
230-
static constexpr bool maybe_skipped = false;
231-
};
232-
221+
233222
template <opts Opts, class T>
234-
requires(reflect<T>::size > 0)
235-
struct object_info<Opts, T>
236-
{
237-
static constexpr auto N = reflect<T>::size;
238-
239-
static constexpr bool maybe_skipped = [] {
240-
if constexpr (N > 0) {
241-
if constexpr (Opts.skip_null_members) {
242-
// if any type could be null then we might skip
243-
return []<size_t... I>(std::index_sequence<I...>) {
244-
return ((detail::always_skipped<field_t<T, I>> || detail::null_t<field_t<T, I>>) || ...);
245-
}(std::make_index_sequence<N>{});
246-
}
247-
else {
248-
// if we have an always_skipped type then we return true
249-
return []<size_t... I>(std::index_sequence<I...>) {
250-
return ((detail::always_skipped<field_t<T, I>>) || ...);
251-
}(std::make_index_sequence<N>{});
252-
}
223+
inline constexpr bool maybe_skipped = [] {
224+
if constexpr (reflect<T>::size > 0)
225+
{
226+
constexpr auto N = reflect<T>::size;
227+
if constexpr (Opts.skip_null_members) {
228+
// if any type could be null then we might skip
229+
return []<size_t... I>(std::index_sequence<I...>) {
230+
return ((detail::always_skipped<field_t<T, I>> || detail::null_t<field_t<T, I>>) || ...);
231+
}(std::make_index_sequence<N>{});
253232
}
254233
else {
255-
return false;
234+
// if we have an always_skipped type then we return true
235+
return []<size_t... I>(std::index_sequence<I...>) {
236+
return ((detail::always_skipped<field_t<T, I>>) || ...);
237+
}(std::make_index_sequence<N>{});
256238
}
257-
}();
258-
};
239+
}
240+
else {
241+
return false;
242+
}
243+
}();
259244
}
260245

261246
namespace glz::detail

include/glaze/json/write.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ namespace glz
16771677
}();
16781678

16791679
static constexpr auto padding = round_up_to_nearest_16(maximum_key_size<T> + write_padding_bytes);
1680-
if constexpr (object_info<Opts, T>::maybe_skipped) {
1680+
if constexpr (maybe_skipped<Opts, T>) {
16811681
bool first = true;
16821682
invoke_table<N>([&]<size_t I>() {
16831683
using val_t = field_t<T, I>;

tests/json_reflection_test/json_reflection_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ struct empty_t
454454
{};
455455

456456
static_assert(glz::reflect<empty_t>::size == 0);
457-
static_assert(not glz::object_info<glz::opts{}, empty_t>::maybe_skipped);
457+
static_assert(not glz::maybe_skipped<glz::opts{}, empty_t>);
458458

459459
suite empty_test = [] {
460460
"empty_t"_test = [] {

0 commit comments

Comments
 (0)