ECSTASY
All in the name
Loading...
Searching...
No Matches
Allocator.hpp
Go to the documentation of this file.
1
11
12#ifndef UTIL_ALLOCATOR_HPP_
13#define UTIL_ALLOCATOR_HPP_
14
15#include <memory>
16#include <vector>
17
18namespace util
19{
26 template <typename Base>
27 class Allocator {
28 public:
42 template <std::derived_from<Base> T, typename... Args>
43 [[nodiscard]] T &instanciate(Args &&...args)
44 {
45 return dynamic_cast<T &>(*_instances.emplace_back(std::make_unique<T>(std::forward<Args>(args)...)).get());
46 }
47
48 private:
50 };
51} // namespace util
52
53#endif /* !UTIL_ALLOCATOR_HPP_ */
T & instanciate(Args &&...args)
Instanciate a new instance of type T with lifetime attached to this lifetime.
Definition Allocator.hpp:43
std::vector< std::unique_ptr< Base > > _instances
Definition Allocator.hpp:49
T emplace_back(T... args)
Namespace regrouping helpers used by ecstasy but not specific to ecstasy.
Definition Queryable.hpp:21