Add cool new c++ 20 constraint to EventHook.
continuous-integration/drone/push Build is failing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-08-14 14:10:13 +02:00
parent 5536a6b83d
commit 103c703208
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 4 additions and 2 deletions

View File

@ -7,6 +7,8 @@
#include "../../Library/Exceptions/CreatureException.hpp" #include "../../Library/Exceptions/CreatureException.hpp"
#include "Events/EventData.hpp" #include "Events/EventData.hpp"
template <class T> concept Event = std::is_base_of<CreatureLib::Battling::EventData, T>::value;
namespace CreatureLib::Battling { namespace CreatureLib::Battling {
/// The Event Hook class allows users to write consumers for the battle events, for example to write User Interfaces /// The Event Hook class allows users to write consumers for the battle events, for example to write User Interfaces
/// for it. /// for it.
@ -39,7 +41,7 @@ namespace CreatureLib::Battling {
size_t GetPosition() const noexcept { return _offset; } size_t GetPosition() const noexcept { return _offset; }
size_t GetCapacity() const noexcept { return _capacity; } size_t GetCapacity() const noexcept { return _capacity; }
template <class T, class... parameters> void Trigger(parameters... args) { template <Event T, class... parameters> void Trigger(parameters... args) {
if (_listeners.size() == 0) if (_listeners.size() == 0)
return; return;

View File

@ -100,7 +100,7 @@ namespace CreatureLib::Battling {
void DisplayText(const ArbUt::StringView& text); void DisplayText(const ArbUt::StringView& text);
void RegisterEventListener(EventHook::EventHookFunc listener) { this->_eventHook.RegisterListener(listener); } void RegisterEventListener(EventHook::EventHookFunc listener) { this->_eventHook.RegisterListener(listener); }
template <class T, class... parameters> void TriggerEventListener(parameters... args) { template <Event T, class... parameters> void TriggerEventListener(parameters... args) {
this->_eventHook.Trigger<T>(args...); this->_eventHook.Trigger<T>(args...);
} }
}; };