QCryptographicHash: constexpr ALL of QSmallByteArray
... because we can. Pick-to: 6.5 Change-Id: I03872a69ac4625ca73b0a7f0310a2a951615b000 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
c513d4fe31
commit
29b55dcb83
@ -132,19 +132,19 @@ public:
|
||||
QSmallByteArray() = default;
|
||||
// all compiler-generated SMFs are ok!
|
||||
template <std::size_t M, std::enable_if_t<M < N, bool> = true> // M == N is for copy ctor!
|
||||
QSmallByteArray(const QSmallByteArray<M> &other) noexcept
|
||||
constexpr QSmallByteArray(const QSmallByteArray<M> &other) noexcept
|
||||
{
|
||||
assign(other);
|
||||
}
|
||||
template <std::size_t M, std::enable_if_t<M < N, bool> = true> // M == N is for copy-assignment op!
|
||||
QSmallByteArray &operator=(const QSmallByteArray<M> &other) noexcept
|
||||
constexpr QSmallByteArray &operator=(const QSmallByteArray<M> &other) noexcept
|
||||
{
|
||||
assign(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Container> // ### underconstrained
|
||||
void assign(const Container &c)
|
||||
constexpr void assign(const Container &c)
|
||||
{
|
||||
const size_t otherSize = size_t(std::size(c));
|
||||
Q_ASSERT(otherSize < N);
|
||||
@ -152,43 +152,43 @@ public:
|
||||
m_size = quint8(otherSize);
|
||||
}
|
||||
|
||||
quint8 *data() noexcept { return m_data.data(); }
|
||||
const quint8 *data() const noexcept { return m_data.data(); }
|
||||
qsizetype size() const noexcept { return qsizetype{m_size}; }
|
||||
quint8 &operator[](qsizetype n)
|
||||
constexpr quint8 *data() noexcept { return m_data.data(); }
|
||||
constexpr const quint8 *data() const noexcept { return m_data.data(); }
|
||||
constexpr qsizetype size() const noexcept { return qsizetype{m_size}; }
|
||||
constexpr quint8 &operator[](qsizetype n)
|
||||
{
|
||||
Q_ASSERT(n < size());
|
||||
return data()[n];
|
||||
}
|
||||
const quint8 &operator[](qsizetype n) const
|
||||
constexpr const quint8 &operator[](qsizetype n) const
|
||||
{
|
||||
Q_ASSERT(n < size());
|
||||
return data()[n];
|
||||
}
|
||||
bool isEmpty() const noexcept { return size() == 0; }
|
||||
void clear() noexcept { m_size = 0; }
|
||||
void resizeForOverwrite(qsizetype s)
|
||||
constexpr bool isEmpty() const noexcept { return size() == 0; }
|
||||
constexpr void clear() noexcept { m_size = 0; }
|
||||
constexpr void resizeForOverwrite(qsizetype s)
|
||||
{
|
||||
Q_ASSERT(s >= 0);
|
||||
Q_ASSERT(size_t(s) <= N);
|
||||
m_size = std::uint8_t(s);
|
||||
}
|
||||
void resize(qsizetype s, quint8 v)
|
||||
constexpr void resize(qsizetype s, quint8 v)
|
||||
{
|
||||
const auto oldSize = size();
|
||||
resizeForOverwrite(s);
|
||||
if (s > oldSize)
|
||||
memset(data() + oldSize, v, size() - oldSize);
|
||||
}
|
||||
QByteArrayView toByteArrayView() const noexcept
|
||||
constexpr QByteArrayView toByteArrayView() const noexcept
|
||||
{ return *this; }
|
||||
|
||||
auto begin() noexcept { return data(); }
|
||||
auto begin() const noexcept { return data(); }
|
||||
auto cbegin() const noexcept { return begin(); }
|
||||
auto end() noexcept { return data() + size(); }
|
||||
auto end() const noexcept { return data() + size(); }
|
||||
auto cend() const noexcept { return end(); }
|
||||
constexpr auto begin() noexcept { return data(); }
|
||||
constexpr auto begin() const noexcept { return data(); }
|
||||
constexpr auto cbegin() const noexcept { return begin(); }
|
||||
constexpr auto end() noexcept { return data() + size(); }
|
||||
constexpr auto end() const noexcept { return data() + size(); }
|
||||
constexpr auto cend() const noexcept { return end(); }
|
||||
};
|
||||
|
||||
static constexpr int hashLengthInternal(QCryptographicHash::Algorithm method) noexcept
|
||||
|
Loading…
Reference in New Issue
Block a user