32 public std::enable_shared_from_this<ObjectPool<T>>
35 std::shared_ptr<T> getObject()
37 static_assert(!std::is_pointer<T>::value,
38 "The parameter type of the ObjectPool template can't be "
42 std::lock_guard<std::mutex> lock(mtx_);
56 std::weak_ptr<ObjectPool<T>> weakPtr = this->shared_from_this();
57 auto obj = std::shared_ptr<T>(p, [weakPtr](T *ptr) {
58 auto self = weakPtr.lock();
61 std::lock_guard<std::mutex> lock(self->mtx_);
62 self->objs_.push_back(ptr);
73 std::vector<T *> objs_;