Add construct, destroy to handler_alloc

fix #432
This commit is contained in:
Vinnie Falco
2017-06-08 19:36:51 -07:00
parent 58c2739115
commit dc4b69d8bc
3 changed files with 32 additions and 8 deletions
+16 -8
View File
@@ -10,6 +10,7 @@
#include <beast/config.hpp>
#include <boost/asio/handler_alloc_hook.hpp>
#include <boost/config.hpp>
#include <cstddef>
#include <cstdlib>
#include <memory>
@@ -96,7 +97,7 @@ public:
}
value_type*
allocate(std::ptrdiff_t n)
allocate(size_type n)
{
auto const size = n * sizeof(T);
using boost::asio::asio_handler_allocate;
@@ -105,21 +106,28 @@ public:
}
void
deallocate(value_type* p, std::ptrdiff_t n)
deallocate(value_type* p, size_type n)
{
auto const size = n * sizeof(T);
using boost::asio::asio_handler_deallocate;
asio_handler_deallocate(p, size, std::addressof(h_));
}
#ifdef _MSC_VER
// Work-around for MSVC not using allocator_traits
// in the implementation of shared_ptr
//
//#if BOOST_WORKAROUND(BOOST_GCC, < 60000) // Works, but too coarse
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 60000
template<class U, class... Args>
void
destroy(T* t)
construct(U* ptr, Args&&... args)
{
t->~T();
::new((void*)ptr) U(std::forward<Args>(args)...);
}
template<class U>
void
destroy(U* ptr)
{
ptr->~U();
}
#endif