mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-22 00:59:08 +01:00
acquire unique_ptr
This commit is contained in:
parent
7ea0249e6e
commit
719de94821
1 changed files with 10 additions and 3 deletions
13
util.h
13
util.h
|
@ -1,9 +1,9 @@
|
||||||
#ifndef UTIL_H
|
#ifndef UTIL_H
|
||||||
#define UTIL_H
|
#define UTIL_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
|
@ -45,7 +45,7 @@ namespace util
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... TArgs>
|
template<typename... TArgs>
|
||||||
T * Acquire (TArgs... args)
|
T * Acquire (TArgs&&... args)
|
||||||
{
|
{
|
||||||
if (!m_Head) return new T(args...);
|
if (!m_Head) return new T(args...);
|
||||||
else
|
else
|
||||||
|
@ -64,6 +64,13 @@ namespace util
|
||||||
m_Head = t;
|
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:
|
private:
|
||||||
|
|
||||||
T * m_Head;
|
T * m_Head;
|
||||||
|
|
Loading…
Add table
Reference in a new issue