Skip to content

Instantly share code, notes, and snippets.

@HowardHinnant
Last active January 4, 2017 18:55
Show Gist options
  • Save HowardHinnant/4fb44b884677503891e95f9ca2b4a978 to your computer and use it in GitHub Desktop.
Save HowardHinnant/4fb44b884677503891e95f9ca2b4a978 to your computer and use it in GitHub Desktop.
struct P
{
T* t;
std::atomic<std::uint16_t> n;
template<class DeducedHandler, class... Args>
P(DeducedHandler&& handler, Args&&... args);
private:
P() noexcept;
};
...
template<class T>
inline
handler_ptr<T>::P::
P() noexcept
: n(1)
{
}
template<class T>
template<class DeducedHandler, class... Args>
inline
handler_ptr<T>::P::
P(DeducedHandler&& handler, Args&&... args)
: P()
{
t = reinterpret_cast<T*>(
boost_asio_handler_alloc_helpers::
allocate(sizeof(T), handler));
t = new(t) T{
std::forward<DeducedHandler>(handler),
std::forward<Args>(args)...};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment