From: Mikko Rasa Date: Tue, 15 Apr 2025 21:50:57 +0000 (+0300) Subject: Allow overriding the base class of BufferedComponent X-Git-Url: https://git.tdb.fi/?a=commitdiff_plain;h=b9d96dc9094b90d1486a044d2822a9df9621d78a;p=libs%2Fgame.git Allow overriding the base class of BufferedComponent It still has to ultimately derive from Component, but this allows inserting an intermediate base class. --- 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>();