From fd1bd3032fa34a70fb2dae99a3b2773b920cc475 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 6 Dec 2024 16:00:03 -0500 Subject: [PATCH] Attempt to move towards at-launch field declaration. This avoids any need for overt thread safety in mutations. --- Reflection/Struct.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Reflection/Struct.hpp b/Reflection/Struct.hpp index 2ba8b47cc..b9261c100 100644 --- a/Reflection/Struct.hpp +++ b/Reflection/Struct.hpp @@ -27,6 +27,12 @@ namespace Reflection { #define DeclareField(Name) declare(&Name, #Name) +#define BeginDeclarations () void declare_fields() { +#define EndDeclarations () } \ + struct Declarer { Declarer() { Target t; t.declare_fields(); } }; \ + static Declarer declarer; + + struct Struct { virtual std::vector all_keys() const = 0; virtual const std::type_info *type_of(const std::string &name) const = 0; @@ -300,7 +306,7 @@ protected: /*! @returns @c true if this subclass of @c Struct has not yet declared any fields. */ - bool needs_declare() { + bool needs_declare() const { return contents_.empty(); }