We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
代码如下 std::unique_ptr<T, DeleterType> get() { if (pool_.empty()) { throw std::logic_error("no more object"); }
//every time add custom deleter for default unique_ptr std::unique_ptr<T, DeleterType> ptr(pool_.back().release(), [this](T* t) { pool_.push_back(std::unique_ptr<T>(t)); }); pool_.pop_back(); return std::move(ptr); }
请教下,代码中使用的lambda表达式中这一句pool_.push_back这句的作用是什么呢?一直没看懂
The text was updated successfully, but these errors were encountered:
就是将用完的对象再放回池子里啊。你看申请的时候是从池子里面取出来,用完之后,由智能指针控制其析构,但它的析构就是将该对象重新放到池子里!
Sorry, something went wrong.
No branches or pull requests
代码如下
std::unique_ptr<T, DeleterType> get()
{
if (pool_.empty())
{
throw std::logic_error("no more object");
}
请教下,代码中使用的lambda表达式中这一句pool_.push_back这句的作用是什么呢?一直没看懂
The text was updated successfully, but these errors were encountered: