28#include <unordered_map>
36 template<
typename T,
typename... Args>
38 const size_t hash =
typeid(T).hash_code();
39 std::shared_ptr<T> instance = std::make_shared<T>(args...);
40 m_instances.emplace(hash, std::shared_ptr<void>(instance));
45 const size_t hash =
typeid(T).hash_code();
46 auto it = m_instances.find(hash);
47 if (it != m_instances.end()) {
48 return std::static_pointer_cast<T>(m_instances.at(hash));
58 std::unordered_map<size_t, std::shared_ptr<void>> m_instances;
Definition: ServiceLocator.hpp:31
service_locator_t()=default
void set_instance(Args... args)
Definition: ServiceLocator.hpp:37
std::shared_ptr< T > get_instance()
Definition: ServiceLocator.hpp:44
void clear()
Definition: ServiceLocator.hpp:53
~service_locator_t()=default