Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serde: Require T::serde_fields for all serde structs #23126

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 0 additions & 178 deletions src/v/serde/envelope_for_each_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,189 +17,11 @@

namespace serde {

namespace detail {

template<typename T>
concept has_serde_fields = requires(T t) { t.serde_fields(); };

} // namespace detail

template<detail::has_serde_fields T>
constexpr inline auto envelope_to_tuple(T&& t) {
return t.serde_fields();
}

template<typename T>
requires(!detail::has_serde_fields<T>)
constexpr inline auto envelope_to_tuple(T& t) {
static_assert(std::is_aggregate_v<T>);
static_assert(std::is_standard_layout_v<T>);
static_assert(!std::is_polymorphic_v<T>);

constexpr auto const a = reflection::arity<T>() - 1;
if constexpr (a == 0) {
return std::tie();
} else if constexpr (a == 1) {
auto& [p1] = t;
return std::tie(p1);
} else if constexpr (a == 2) {
auto& [p1, p2] = t;
return std::tie(p1, p2);
} else if constexpr (a == 3) {
auto& [p1, p2, p3] = t;
return std::tie(p1, p2, p3);
} else if constexpr (a == 4) {
auto& [p1, p2, p3, p4] = t;
return std::tie(p1, p2, p3, p4);
} else if constexpr (a == 5) {
auto& [p1, p2, p3, p4, p5] = t;
return std::tie(p1, p2, p3, p4, p5);
} else if constexpr (a == 6) {
auto& [p1, p2, p3, p4, p5, p6] = t;
return std::tie(p1, p2, p3, p4, p5, p6);
} else if constexpr (a == 7) {
auto& [p1, p2, p3, p4, p5, p6, p7] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7);
} else if constexpr (a == 8) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7, p8);
} else if constexpr (a == 9) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9);
} else if constexpr (a == 10) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
} else if constexpr (a == 11) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
} else if constexpr (a == 12) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12);
} else if constexpr (a == 13) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13] = t;
return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13);
} else if constexpr (a == 14) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14] = t;
return std::tie(
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14);
} else if constexpr (a == 15) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15]
= t;
return std::tie(
p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15);
} else if constexpr (a == 16) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16]
= t;
return std::tie(
p1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16);
} else if constexpr (a == 17) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17]
= t;
return std::tie(
p1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17);
} else if constexpr (a == 18) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18]
= t;
return std::tie(
p1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17,
p18);
} else if constexpr (a == 19) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19]
= t;
return std::tie(
p1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17,
p18,
p19);
} else if constexpr (a == 20) {
auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20]
= t;
return std::tie(
p1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17,
p18,
p19,
p20);
}
}

template<typename Fn>
concept check_for_more_fn = requires(Fn&& fn, int& f) {
{ fn(f) } -> std::convertible_to<bool>;
Expand Down