Browse Source

acquire unique_ptr

pull/777/head
orignal 8 years ago
parent
commit
719de94821
  1. 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…
Cancel
Save