diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df06914..f757e900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Version 51 * Use BOOST_FALLTHROUGH * Use BOOST_STRINGIZE * DynamicBuffer benchmarks +* Add construct, destroy to handler_alloc API Changes: diff --git a/include/beast/core/handler_alloc.hpp b/include/beast/core/handler_alloc.hpp index af999989..492d84b6 100644 --- a/include/beast/core/handler_alloc.hpp +++ b/include/beast/core/handler_alloc.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -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 void - destroy(T* t) + construct(U* ptr, Args&&... args) { - t->~T(); + ::new((void*)ptr) U(std::forward(args)...); + } + + template + void + destroy(U* ptr) + { + ptr->~U(); } #endif diff --git a/test/core/handler_alloc.cpp b/test/core/handler_alloc.cpp index c657d5fb..64acc074 100644 --- a/test/core/handler_alloc.cpp +++ b/test/core/handler_alloc.cpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace beast { @@ -24,9 +25,23 @@ public: } }; + // https://github.com/vinniefalco/Beast/issues/432 + void + testRegression432() + { + handler h; + handler_alloc a{h}; + std::list> v{a}; + v.push_back(1); + v.push_back(2); + v.push_back(3); + } + void run() override { + testRegression432(); + handler h; handler h2; handler_alloc a1{h};