diff options
Diffstat (limited to 'src/crepe/ComponentManager.hpp')
-rw-r--r-- | src/crepe/ComponentManager.hpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/crepe/ComponentManager.hpp b/src/crepe/ComponentManager.hpp index 999cdcf..084cd33 100644 --- a/src/crepe/ComponentManager.hpp +++ b/src/crepe/ComponentManager.hpp @@ -1,13 +1,17 @@ #pragma once +#include <type_traits> + #include "ComponentManager.h" namespace crepe { -template <typename T, typename... Args> +template <class T, typename... Args> void ComponentManager::add_component(uint32_t id, Args &&... args) { using namespace std; + static_assert(is_base_of<Component, T>::value, "add_component must recieve a derivative class of Component"); + // Determine the type of T (this is used as the key of the unordered_map<>) type_index type = typeid(T); @@ -23,9 +27,11 @@ void ComponentManager::add_component(uint32_t id, Args &&... args) { components[type].resize(id + 1); } - // Create a new component of type T using perfect forwarding and store its - // unique_ptr in the vector<> - components[type][id].push_back(make_unique<T>(forward<Args>(args)...)); + // Create a new component of type T (arguments directly forwarded). The + // constructor must be called by ComponentManager. + T * instance = new T(forward<Args>(args)...); + // store its unique_ptr in the vector<> + components[type][id].push_back(unique_ptr<T>(instance)); } template <typename T> |