1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-13 19:37:51 +00:00

acquire unique_ptr

This commit is contained in:
orignal 2017-01-11 19:45:04 -05:00
parent 7ea0249e6e
commit 719de94821

13
util.h
View File

@ -1,9 +1,9 @@
#ifndef UTIL_H
#define UTIL_H
#include <map>
#include <string>
#include <iostream>
#include <functional>
#include <memory>
#include <boost/asio.hpp>
#ifdef ANDROID
@ -45,7 +45,7 @@ namespace util
}
template<typename... TArgs>
T * Acquire (TArgs... args)
T * Acquire (TArgs&&... args)
{
if (!m_Head) return new T(args...);
else
@ -64,6 +64,13 @@ namespace util
m_Head = t;
}
template<typename... TArgs>
std::unique_ptr<T, std::function<void(T*)> > AcquireUnique (TArgs&&... args)
{
return std::unique_ptr<T, std::function<void(T*)> >(Acquire (args...),
std::bind (&MemoryPool<T>::Release, this, std::placeholders::_1));
}
private:
T * m_Head;