36 std::array<quint8, N> m_data;
37 static_assert(N <= (std::numeric_limits<std::uint8_t>::max)());
40 QSmallByteArray() =
default;
42 template <std::size_t M, std::enable_if_t<M < N,
bool> =
true>
43 constexpr QSmallByteArray(
const QSmallByteArray<M> &other)
noexcept
47 template <std::size_t M, std::enable_if_t<M < N,
bool> =
true>
48 constexpr QSmallByteArray &operator=(
const QSmallByteArray<M> &other)
noexcept
54 template <
typename Container>
55 constexpr void assign(
const Container &c)
57 const size_t otherSize = size_t(std::size(c));
58 Q_ASSERT(otherSize < N);
59 memcpy(data(), std::data(c), otherSize);
60 m_size = quint8(otherSize);
63 constexpr quint8 *data()
noexcept {
return m_data.data(); }
64 constexpr const quint8 *data()
const noexcept {
return m_data.data(); }
65 constexpr qsizetype size()
const noexcept {
return qsizetype{m_size}; }
66 constexpr quint8 &operator[](qsizetype n)
71 constexpr const quint8 &operator[](qsizetype n)
const
76 constexpr bool isEmpty()
const noexcept {
return size() == 0; }
77 constexpr void clear()
noexcept { m_size = 0; }
78 constexpr void resizeForOverwrite(qsizetype s)
81 Q_ASSERT(size_t(s) <= N);
82 m_size = std::uint8_t(s);
84 constexpr void resize(qsizetype s, quint8 v)
86 const auto oldSize = size();
87 resizeForOverwrite(s);
89 memset(data() + oldSize, v, size() - oldSize);
91 constexpr QByteArrayView toByteArrayView()
const noexcept
94 constexpr auto begin()
noexcept {
return data(); }
95 constexpr auto begin()
const noexcept {
return data(); }
96 constexpr auto cbegin()
const noexcept {
return begin(); }
97 constexpr auto end()
noexcept {
return data() + size(); }
98 constexpr auto end()
const noexcept {
return data() + size(); }
99 constexpr auto cend()
const noexcept {
return end(); }