From 3cae96cc3017f7d3325f0e1f20bc7960595ad310 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 9 Apr 2024 15:08:01 +0200 Subject: w --- serialize/savegame.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/serialize/savegame.cpp b/serialize/savegame.cpp index df541634..831dbf06 100644 --- a/serialize/savegame.cpp +++ b/serialize/savegame.cpp @@ -148,14 +148,15 @@ struct visitor_ using o_sc_g = qual2; using o_sc_door = qual2; - Derived& self = static_cast(*this); + template requires (!IsWriter) static CORRADE_ALWAYS_INLINE void visit(T& x, F&& f) { f(x); } + template requires (IsWriter) static CORRADE_ALWAYS_INLINE void visit(T x, F&& f) { f(x); } - template - requires (!IsWriter) - static CORRADE_ALWAYS_INLINE void visit(T& x, F&& f) - { - f(forward(x)); - } + CORRADE_ALWAYS_INLINE Derived& derived() { return static_cast(*this); } + + template requires (!IsWriter) CORRADE_ALWAYS_INLINE void visit(E& x, F&& f) + { using U = std::underlying_type_t>; auto xʹ = U(x); f(xʹ); } + template requires (IsWriter) CORRADE_ALWAYS_INLINE void visit(E x, F&& f) + { using U = std::underlying_type_t; f(static_cast(x)); } template void visit(T&& x, F&& f) { @@ -164,15 +165,11 @@ struct visitor_ visit(forward(x).data()[i], f); } - template requires (!IsWriter) CORRADE_ALWAYS_INLINE void visit(E& x, F&& f) - { using U = std::underlying_type_t>; auto xʹ = U(x); f(xʹ); } - - template requires (IsWriter) CORRADE_ALWAYS_INLINE void visit(E x, F&& f) - { using U = std::underlying_type_t; f(static_cast(x)); } - template void visit_object_header(o_object& obj, const object_header_s& s, F&& f) { + auto& self = derived(); + visit(s.id, f); fm_soft_assert(s.id != 0); visit(s.type, f); @@ -314,6 +311,8 @@ struct visitor_ template void visit_object_proto(o_critter& obj, critter_header_s&& s, F&& f) { + auto& self = derived(); + self.visit(obj.name, f); if (self.PROTO >= 22) [[likely]] -- cgit v1.2.3