Skip to content

Commit 5fac89e

Browse files
committed
fix the error when count of struct field is zero
1 parent 420794a commit 5fac89e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

include/magic/struct.h

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,24 @@ namespace magic::details
128128
constexpr auto true_count_of_fields()
129129
{
130130
constexpr auto max = total_count_of_fields<T>();
131-
std::array<std::size_t, max> indices = {1};
132-
search_all_extra_index<T>(indices);
133-
std::size_t result = max;
134-
std::size_t index = 0;
135-
while (index < max)
131+
if constexpr (max == 0)
136132
{
137-
auto n = indices[index];
138-
result -= n - 1;
139-
index += n;
133+
return 0;
134+
}
135+
else
136+
{
137+
std::array<std::size_t, max> indices = {1};
138+
search_all_extra_index<T>(indices);
139+
std::size_t result = max;
140+
std::size_t index = 0;
141+
while (index < max)
142+
{
143+
auto n = indices[index];
144+
result -= n - 1;
145+
index += n;
146+
}
147+
return result;
140148
}
141-
return result;
142149
}
143150
} // namespace magic::details
144151
namespace magic
@@ -179,7 +186,7 @@ namespace magic::details
179186
constexpr auto field_types_of_impl(T object)
180187
{
181188
constexpr auto N = field_count_of<T>();
182-
// clang-format off
189+
// clang-format off
183190
#include "generate/struct_bind_of_field_types.code"
184191
// clang-format on
185192
}
@@ -189,7 +196,7 @@ namespace magic::details
189196
{
190197
using T = std::remove_cvref_t<decltype(object)>;
191198
constexpr auto N = field_count_of<T>();
192-
// clang-format off
199+
// clang-format off
193200
#include "generate/struct_bind_of_field_access.code"
194201
// clang-format on
195202
}

0 commit comments

Comments
 (0)