From d6d18f7b085329c5ebcd733e03828f74bdcc2a25 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sun, 14 Mar 2021 17:04:36 -0700 Subject: [PATCH] ircd::buffer: Add non-char array convenience cast constructions. --- include/ircd/buffer/const_buffer.h | 8 ++++++++ include/ircd/buffer/mutable_buffer.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/ircd/buffer/const_buffer.h b/include/ircd/buffer/const_buffer.h index 5dffe1543..39cf7ec49 100644 --- a/include/ircd/buffer/const_buffer.h +++ b/include/ircd/buffer/const_buffer.h @@ -21,6 +21,7 @@ struct ircd::buffer::const_buffer void insert(const char *const &, const char &); using buffer::buffer; + template explicit const_buffer(const T (&)[SIZE]); template const_buffer(const char (&buf)[SIZE]); template const_buffer(const std::array &buf); const_buffer(const buffer &b); @@ -74,6 +75,13 @@ ircd::buffer::const_buffer::const_buffer(const std::array &buf) :buffer{reinterpret_cast(buf.data()), SIZE} {} +template +inline __attribute__((always_inline)) +ircd::buffer::const_buffer::const_buffer(const T (&buf)[SIZE]) +:buffer{reinterpret_cast(buf), SIZE * sizeof(T)} +{} + #ifndef _NDEBUG __attribute__((noreturn)) #endif diff --git a/include/ircd/buffer/mutable_buffer.h b/include/ircd/buffer/mutable_buffer.h index 90ff71a1b..255e802fa 100644 --- a/include/ircd/buffer/mutable_buffer.h +++ b/include/ircd/buffer/mutable_buffer.h @@ -27,6 +27,7 @@ struct ircd::buffer::mutable_buffer void insert(char *const &it, const value_type &v); using buffer::buffer; + template explicit mutable_buffer(T (&)[SIZE]); template mutable_buffer(char (&buf)[SIZE]); template mutable_buffer(std::array &buf); mutable_buffer(const std::function &); @@ -68,6 +69,13 @@ ircd::buffer::mutable_buffer::mutable_buffer(std::array &buf) :buffer{buf.data(), SIZE} {} +template +inline __attribute__((always_inline)) +ircd::buffer::mutable_buffer::mutable_buffer(T (&buf)[SIZE]) +:buffer{reinterpret_cast(buf), SIZE * sizeof(T)} +{} + inline void ircd::buffer::mutable_buffer::insert(char *const &it, const value_type &v)