From b9d96dc9094b90d1486a044d2822a9df9621d78a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 16 Apr 2025 00:50:57 +0300 Subject: [PATCH] Allow overriding the base class of BufferedComponent It still has to ultimately derive from Component, but this allows inserting an intermediate base class. --- source/game/component.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/game/component.h b/source/game/component.h index 6127cd4..9b78f96 100644 --- a/source/game/component.h +++ b/source/game/component.h @@ -25,8 +25,9 @@ public: Handle get_entity() const { return entity; } }; -template -class BufferedComponent: public Component +template + requires std::is_base_of_v +class BufferedComponent: public Base { public: using Data = T; @@ -38,7 +39,7 @@ private: bool written = false; protected: - BufferedComponent(Handle e): Component(e) { } + using Base::Base; const T &read() const; T &write(); @@ -51,8 +52,9 @@ public: bool was_written() const { return written; } }; -template -const T &BufferedComponent::read() const +template + requires std::is_base_of_v +const T &BufferedComponent::read() const { #ifdef DEBUG AccessGuard::get_instance().check>(); @@ -60,8 +62,9 @@ const T &BufferedComponent::read() const return data[read_index&1]; } -template -T &BufferedComponent::write() +template + requires std::is_base_of_v +T &BufferedComponent::write() { #ifdef DEBUG AccessGuard::get_instance().check>(); -- 2.45.2