// Matrix Construct // // Copyright (C) Matrix Construct Developers, Authors & Contributors // Copyright (C) 2016-2018 Jason Volk // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice is present in all copies. The // full license for this software is available in the LICENSE file. #pragma once #define HAVE_IRCD_BUFFER_FIXED_BUFFER_H /// fixed_buffer wraps an std::array with construction and conversions apropos /// the ircd::buffer suite. fixed_buffer should be punnable. Its only memory /// footprint is the array itself and /// template struct ircd::buffer::fixed_buffer :std::array::type, SIZE> { using mutable_type = typename std::remove_const::type; using const_type = typename std::add_const::type; using array_type = std::array; using proto_type = void (const mutable_buffer &); using args_type = const mutable_buffer &; operator buffer_type() const noexcept; operator buffer_type() noexcept; using array_type::array_type; template fixed_buffer(F&&, typename std::enable_if::value, void>::type * = nullptr); explicit fixed_buffer(nullptr_t) noexcept; fixed_buffer(const buffer_type &b) noexcept; fixed_buffer() = default; }; static_assert ( // Assertion over an arbitrary but common template configuration. std::is_standard_layout>::value, "ircd::buffer::fixed_buffer must be standard layout" ); template template inline ircd::buffer::fixed_buffer::fixed_buffer(F&& closure, typename std::enable_if::value, void>::type *) { const mutable_buffer buf { reinterpret_cast(this->data()), SIZE }; closure(buf); } template inline ircd::buffer::fixed_buffer::fixed_buffer(const buffer_type &b) noexcept :array_type { std::begin(b), std::end(b) } {} template inline ircd::buffer::fixed_buffer::fixed_buffer(nullptr_t) noexcept :array_type{{0}} {} template inline ircd::buffer::fixed_buffer::operator buffer_type() noexcept { return buffer_type { this->data(), SIZE, }; } template inline ircd::buffer::fixed_buffer::operator buffer_type() const noexcept { return buffer_type { this->data(), SIZE, }; }