21 using Factory = std::function<_unique<T>()>;
24 std::shared_ptr<bool> mPoolAlive = std::make_shared<bool>(
true);
27 template <
typename Ptr = _<T>>
28 Ptr getImpl()
noexcept {
33 t = std::move(mQueue.front());
36 if constexpr (std::is_same_v<Ptr, _<T>>) {
39 return std::unique_ptr<T, APoolDeleter>(t.release(),
APoolDeleter(
this));
44 explicit APool(Factory factory) noexcept : mFactory(std::move(factory)) {}
48 std::shared_ptr<bool> poolAlive;
50 APoolDeleter(APool<T>* pool) : pool(pool), poolAlive(pool->mPoolAlive) {}
52 void operator()(T* t) {
54 pool->mQueue.push(_unique<T>(t));
65 return getImpl<_<T>>();
68 using UniquePtr = std::unique_ptr<T, APoolDeleter>;
70 auto getUnique() noexcept {
71 return getImpl<UniquePtr>();
static _< T > manage(T *raw)
Delegates memory management of the raw pointer T* raw to the shared pointer, which is returned.
Definition SharedPtrTypes.h:372