1#ifndef ALIGNEDBUFFER_HH
2#define ALIGNEDBUFFER_HH
33 [[nodiscard]]
auto* p() {
return std::bit_cast< uint8_t*>(
this); }
34 [[nodiscard]]
auto* p()
const {
return std::bit_cast<const uint8_t*>(
this); }
37 static constexpr auto ALIGNMENT =
alignof(std::max_align_t);
39 [[nodiscard]]
operator uint8_t*() {
return p(); }
40 [[nodiscard]]
operator const uint8_t*()
const {
return p(); }
41 [[nodiscard]]
auto*
data() {
return p(); }
42 [[nodiscard]]
const auto*
data()
const {
return p(); }
44 template<std::
integral I>
46 template<std::
integral I>
49 template<std::
integral I>
50 [[nodiscard]]
auto&
operator[](I i) {
return *(p() + i); }
51 template<std::
integral I>
52 [[nodiscard]]
const auto&
operator[](I i)
const {
return *(p() + i); }
62 [[nodiscard]]
auto size()
const {
return dat.size(); }
63 [[nodiscard]]
auto*
data() {
return dat.data(); }
64 [[nodiscard]]
auto*
data()
const {
return dat.data(); }
65 [[nodiscard]]
auto begin() {
return dat.begin(); }
66 [[nodiscard]]
auto begin()
const {
return dat.begin(); }
67 [[nodiscard]]
auto end() {
return dat.end(); }
68 [[nodiscard]]
auto end()
const {
return dat.end(); }
71 std::array<uint8_t, N> dat;
76static_assert(
sizeof(AlignedByteArray<32>) == 32,
77 "we rely on the empty-base optimization");
84template<
typename T> [[nodiscard]]
static inline T aligned_cast(
void* p)
86 static_assert(std::is_pointer_v<T>,
87 "can only perform aligned_cast on pointers");
88 assert((std::bit_cast<uintptr_t>(p) %
89 alignof(std::remove_pointer_t<T>)) == 0);
90 return std::bit_cast<T>(p);
friend const auto * operator+(const AlignedBuffer &b, I i)
const auto & operator[](I i) const
static constexpr auto ALIGNMENT
const auto * data() const
friend auto * operator+(AlignedBuffer &b, I i)
This file implemented 3 utility functions: