diff --git a/include/ircd/buffer.h b/include/ircd/buffer.h index 2b932df79..269eb8612 100644 --- a/include/ircd/buffer.h +++ b/include/ircd/buffer.h @@ -209,6 +209,67 @@ struct ircd::buffer::const_raw_buffer {} }; +/// Like unique_ptr, this template holds ownership of an allocated buffer +/// +/// +template +struct ircd::buffer::unique_buffer +:buffer +{ + unique_buffer(std::unique_ptr &&, const size_t &size); + unique_buffer(const size_t &size); + unique_buffer() = default; + unique_buffer(unique_buffer &&) noexcept; + unique_buffer(const unique_buffer &) = delete; + ~unique_buffer() noexcept; +}; + +template +ircd::buffer::unique_buffer::unique_buffer(std::unique_ptr &&b, + const size_t &size) +:buffer +{ + typename buffer::value_type(b.release()), size +} +{ +} + +template +ircd::buffer::unique_buffer::unique_buffer(const size_t &size) +:unique_buffer +{ + std::unique_ptr + { + new __attribute__((aligned(alignment))) uint8_t[size] + }, + size +} +{ +} + +template +ircd::buffer::unique_buffer::unique_buffer(unique_buffer &&other) +noexcept +:buffer +{ + std::move(other) +} +{ + get<0>(other) = nullptr; +} + +template +ircd::buffer::unique_buffer::~unique_buffer() +noexcept +{ + delete[] data(*this); +} + template class buffers, class T> @@ -427,64 +488,3 @@ const { return { get<0>(*this), get<1>(*this) }; } - -/// Like unique_ptr, this template holds ownership of an allocated buffer -/// -/// -template -struct ircd::buffer::unique_buffer -:buffer -{ - unique_buffer(std::unique_ptr &&, const size_t &size); - unique_buffer(const size_t &size); - unique_buffer() = default; - unique_buffer(unique_buffer &&) noexcept; - unique_buffer(const unique_buffer &) = delete; - ~unique_buffer() noexcept; -}; - -template -ircd::buffer::unique_buffer::unique_buffer(std::unique_ptr &&b, - const size_t &size) -:buffer -{ - typename buffer::value_type(b.release()), size -} -{ -} - -template -ircd::buffer::unique_buffer::unique_buffer(const size_t &size) -:unique_buffer -{ - std::unique_ptr - { - new __attribute__((aligned(alignment))) uint8_t[size] - }, - size -} -{ -} - -template -ircd::buffer::unique_buffer::unique_buffer(unique_buffer &&other) -noexcept -:buffer -{ - std::move(other) -} -{ - get<0>(other) = nullptr; -} - -template -ircd::buffer::unique_buffer::~unique_buffer() -noexcept -{ - delete[] data(*this); -}