37 std::array<quint8, N> m_data;
38 static_assert(N <= (std::numeric_limits<std::uint8_t>::max)());
41 QSmallByteArray() =
default;
43 template <std::size_t M, std::enable_if_t<M < N,
bool> =
true>
44 constexpr QSmallByteArray(
const QSmallByteArray<M> &other)
noexcept
48 template <std::size_t M, std::enable_if_t<M < N,
bool> =
true>
49 constexpr QSmallByteArray &operator=(
const QSmallByteArray<M> &other)
noexcept
55 template <
typename Container>
56 constexpr void assign(
const Container &c)
58 const size_t otherSize = size_t(std::size(c));
59 Q_ASSERT(otherSize < N);
60 memcpy(data(), std::data(c), otherSize);
61 m_size = quint8(otherSize);
64 constexpr quint8 *data()
noexcept {
return m_data.data(); }
65 constexpr const quint8 *data()
const noexcept {
return m_data.data(); }
66 constexpr qsizetype size()
const noexcept {
return qsizetype{m_size}; }
67 constexpr quint8 &operator[](qsizetype n)
72 constexpr const quint8 &operator[](qsizetype n)
const
77 constexpr bool isEmpty()
const noexcept {
return size() == 0; }
78 constexpr void clear()
noexcept { m_size = 0; }
79 constexpr void resizeForOverwrite(qsizetype s)
82 Q_ASSERT(size_t(s) <= N);
83 m_size = std::uint8_t(s);
85 constexpr void resize(qsizetype s, quint8 v)
87 const auto oldSize = size();
88 resizeForOverwrite(s);
90 memset(data() + oldSize, v, size() - oldSize);
92 constexpr QByteArrayView toByteArrayView()
const noexcept
95 constexpr auto begin()
noexcept {
return data(); }
96 constexpr auto begin()
const noexcept {
return data(); }
97 constexpr auto cbegin()
const noexcept {
return begin(); }
98 constexpr auto end()
noexcept {
return data() + size(); }
99 constexpr auto end()
const noexcept {
return data() + size(); }
100 constexpr auto cend()
const noexcept {
return end(); }