0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-18 07:50:57 +01:00

ircd::buffer: Add non-char array convenience cast constructions.

This commit is contained in:
Jason Volk 2021-03-14 17:04:36 -07:00
parent 5d6554b1a3
commit d6d18f7b08
2 changed files with 16 additions and 0 deletions

View file

@ -21,6 +21,7 @@ struct ircd::buffer::const_buffer
void insert(const char *const &, const char &); void insert(const char *const &, const char &);
using buffer<const char *>::buffer; using buffer<const char *>::buffer;
template<class T, size_t SIZE> explicit const_buffer(const T (&)[SIZE]);
template<size_t SIZE> const_buffer(const char (&buf)[SIZE]); template<size_t SIZE> const_buffer(const char (&buf)[SIZE]);
template<size_t SIZE> const_buffer(const std::array<char, SIZE> &buf); template<size_t SIZE> const_buffer(const std::array<char, SIZE> &buf);
const_buffer(const buffer<const char *> &b); const_buffer(const buffer<const char *> &b);
@ -74,6 +75,13 @@ ircd::buffer::const_buffer::const_buffer(const std::array<char, SIZE> &buf)
:buffer<const char *>{reinterpret_cast<const char *>(buf.data()), SIZE} :buffer<const char *>{reinterpret_cast<const char *>(buf.data()), SIZE}
{} {}
template<class T,
size_t SIZE>
inline __attribute__((always_inline))
ircd::buffer::const_buffer::const_buffer(const T (&buf)[SIZE])
:buffer<const char *>{reinterpret_cast<const char *>(buf), SIZE * sizeof(T)}
{}
#ifndef _NDEBUG #ifndef _NDEBUG
__attribute__((noreturn)) __attribute__((noreturn))
#endif #endif

View file

@ -27,6 +27,7 @@ struct ircd::buffer::mutable_buffer
void insert(char *const &it, const value_type &v); void insert(char *const &it, const value_type &v);
using buffer<char *>::buffer; using buffer<char *>::buffer;
template<class T, size_t SIZE> explicit mutable_buffer(T (&)[SIZE]);
template<size_t SIZE> mutable_buffer(char (&buf)[SIZE]); template<size_t SIZE> mutable_buffer(char (&buf)[SIZE]);
template<size_t SIZE> mutable_buffer(std::array<char, SIZE> &buf); template<size_t SIZE> mutable_buffer(std::array<char, SIZE> &buf);
mutable_buffer(const std::function<void (const mutable_buffer &)> &); mutable_buffer(const std::function<void (const mutable_buffer &)> &);
@ -68,6 +69,13 @@ ircd::buffer::mutable_buffer::mutable_buffer(std::array<char, SIZE> &buf)
:buffer<char *>{buf.data(), SIZE} :buffer<char *>{buf.data(), SIZE}
{} {}
template<class T,
size_t SIZE>
inline __attribute__((always_inline))
ircd::buffer::mutable_buffer::mutable_buffer(T (&buf)[SIZE])
:buffer<char *>{reinterpret_cast<char *>(buf), SIZE * sizeof(T)}
{}
inline void inline void
ircd::buffer::mutable_buffer::insert(char *const &it, ircd::buffer::mutable_buffer::insert(char *const &it,
const value_type &v) const value_type &v)