Skip to content

Commit 1c13e41

Browse files
code cleanups and compiler warning fixes
Signed-off-by: Christian Parpart <[email protected]>
1 parent 1ef843f commit 1c13e41

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

include/reflection-cpp/reflection.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace detail
7777
};
7878

7979
template <const std::string_view&... Strs>
80-
inline constexpr std::string_view join()
80+
constexpr std::string_view join()
8181
{
8282
constexpr auto joined_arr = []() {
8383
constexpr size_t len = (Strs.size() + ... + 0);
@@ -178,14 +178,14 @@ elisp functions to fill the ToTuple function
178178

179179
template <class T, size_t N = CountMembers<T>>
180180
requires(N <= MaxReflectionMemerCount)
181-
inline constexpr decltype(auto) ToTuple(T&& t) noexcept
181+
constexpr decltype(auto) ToTuple(T&& t) noexcept
182182
{
183183
if constexpr (N == 0)
184184
return std::tuple {};
185185
// clang-format off
186186
else if constexpr (N == 1)
187187
{
188-
auto& [p0] = t;
188+
auto& [p0] = std::forward<T>(t); // TODO: We need to fix the gen script and apply that to all the cases below
189189
return std::tie(p0);
190190
}
191191
else if constexpr (N == 2)
@@ -795,7 +795,7 @@ std::string Inspect(std::vector<Object> const& objects)
795795
}
796796

797797
template <typename Object, typename Callback>
798-
void CollectDifferences(const Object& lhs, const Object& rhs, Callback&& callback)
798+
void CollectDifferences(const Object& lhs, const Object& rhs, Callback const& callback)
799799
{
800800
template_for<0, CountMembers<Object>>([&]<auto I>() {
801801
if constexpr (std::equality_comparable<MemberTypeOf<I, Object>>)
@@ -814,7 +814,7 @@ void CollectDifferences(const Object& lhs, const Object& rhs, Callback&& callbac
814814

815815
template <typename Object, typename Callback>
816816
requires std::same_as<void, std::invoke_result_t<Callback, size_t, MemberTypeOf<0, Object>, MemberTypeOf<0, Object>>>
817-
void CollectDifferences(const Object& lhs, const Object& rhs, Callback&& callback)
817+
void CollectDifferences(const Object& lhs, const Object& rhs, Callback const& callback)
818818
{
819819
template_for<0, CountMembers<Object>>([&]<auto I>() {
820820
if constexpr (std::equality_comparable<MemberTypeOf<I, Object>>)

test-reflection-cpp.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ TEST_CASE("EnumerateMembers.index_and_type", "[reflection]")
118118
Reflection::EnumerateMembers<Person>([]<auto I, typename T>() {
119119
if constexpr (I == 0)
120120
{
121-
static_assert(std::same_as<T,std::string_view>);
121+
static_assert(std::same_as<T, std::string_view>);
122122
}
123123
if constexpr (I == 1)
124124
{
125-
static_assert(std::same_as<T,std::string>);
125+
static_assert(std::same_as<T, std::string>);
126126
}
127127
if constexpr (I == 2)
128128
{
129-
static_assert(std::same_as<T,int>);
129+
static_assert(std::same_as<T, int>);
130130
}
131131
});
132132
}
@@ -203,23 +203,20 @@ TEST_CASE("Compare.simple", "[reflection]")
203203
CHECK(diff == "id: 1 != 2\nname: John Doe != Jane Doe\nage: 42 != 43\n");
204204
}
205205

206-
207-
208206
TEST_CASE("Compare.simple_with_indexing", "[reflection]")
209207
{
210208
auto const r1 = Record { .id = 1, .name = "John Doe", .age = 42 };
211209
auto const r2 = Record { .id = 2, .name = "John Doe", .age = 42 };
212210

213-
size_t check = -1;
214-
auto differenceCallback = [&](size_t ind, auto const& lhs, auto const& rhs) {
215-
check = ind;
211+
size_t check = static_cast<size_t>(-1);
212+
auto differenceCallback = [&](size_t index, auto const& /*lhs*/, auto const& /*rhs*/) {
213+
check = index;
216214
};
217215

218216
Reflection::CollectDifferences(r1, r2, differenceCallback);
219217
CHECK(check == 0);
220218
}
221219

222-
223220
struct Table
224221
{
225222
Record first;

0 commit comments

Comments
 (0)