QByteArrayView: make conversion to string_view constexpr
Both QByteArrayView and std::string_view are Literal Types, so the
conversion between them should be constexpr.
Amends 96d67da420.
Found in API-review.
Pick-to: 6.7
Change-Id: Ic513ce32aa2a743ca890dc05a683a62c0f3a7d50
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
bb10
parent
aadf1d447c
commit
f9474364ee
|
|
@ -303,7 +303,7 @@ public:
|
|||
[[nodiscard]] constexpr char front() const { Q_ASSERT(!empty()); return m_data[0]; }
|
||||
[[nodiscard]] constexpr char back() const { Q_ASSERT(!empty()); return m_data[m_size - 1]; }
|
||||
|
||||
[[nodiscard]] Q_IMPLICIT operator std::string_view() const noexcept
|
||||
[[nodiscard]] constexpr Q_IMPLICIT operator std::string_view() const noexcept
|
||||
{ return std::string_view(m_data, size_t(m_size)); }
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -197,6 +197,10 @@ void tst_QByteArrayView::constExpr() const
|
|||
static_assert(bv.isEmpty());
|
||||
static_assert(bv.data() == nullptr);
|
||||
|
||||
constexpr std::string_view sv = bv;
|
||||
static_assert(sv.size() == 0);
|
||||
static_assert(sv.data() == nullptr);
|
||||
|
||||
constexpr QByteArrayView bv2(bv.data(), bv.data() + bv.size());
|
||||
static_assert(bv2.isNull());
|
||||
static_assert(bv2.empty());
|
||||
|
|
@ -209,6 +213,10 @@ void tst_QByteArrayView::constExpr() const
|
|||
static_assert(bv.isEmpty());
|
||||
static_assert(bv.data() != nullptr);
|
||||
|
||||
constexpr std::string_view sv = bv;
|
||||
static_assert(sv.size() == bv.size());
|
||||
static_assert(sv.data() == bv.data());
|
||||
|
||||
constexpr QByteArrayView bv2(bv.data(), bv.data() + bv.size());
|
||||
static_assert(!bv2.isNull());
|
||||
static_assert(bv2.empty());
|
||||
|
|
@ -241,6 +249,14 @@ void tst_QByteArrayView::constExpr() const
|
|||
static_assert(bv.rbegin() != bv.rend());
|
||||
static_assert(bv.crbegin() != bv.crend());
|
||||
|
||||
constexpr std::string_view sv = bv;
|
||||
static_assert(sv.size() == bv.size());
|
||||
static_assert(sv.data() == bv.data());
|
||||
#ifdef AMBIGUOUS_CALL // QTBUG-108805
|
||||
static_assert(sv == bv);
|
||||
static_assert(bv == sv);
|
||||
#endif
|
||||
|
||||
constexpr QByteArrayView bv2(bv.data(), bv.data() + bv.size());
|
||||
static_assert(!bv2.isNull());
|
||||
static_assert(!bv2.empty());
|
||||
|
|
@ -266,6 +282,13 @@ void tst_QByteArrayView::constExpr() const
|
|||
static_assert(bv.at(4) == 'o');
|
||||
static_assert(bv.back() == 'o');
|
||||
static_assert(bv.last() == 'o');
|
||||
|
||||
constexpr std::string_view sv = bv;
|
||||
static_assert(bv.size() == sv.size());
|
||||
#ifdef AMBIGUOUS_CALL // QTBUG-108805
|
||||
static_assert(bv == sv);
|
||||
static_assert(sv == bv);
|
||||
#endif
|
||||
}
|
||||
{
|
||||
static constexpr char hello[] = { 'H', 'e', 'l', 'l', 'o' };
|
||||
|
|
@ -283,6 +306,13 @@ void tst_QByteArrayView::constExpr() const
|
|||
static_assert(bv.at(4) == 'o');
|
||||
static_assert(bv.back() == 'o');
|
||||
static_assert(bv.last() == 'o');
|
||||
|
||||
constexpr std::string_view sv = bv;
|
||||
static_assert(bv.size() == sv.size());
|
||||
#ifdef AMBIGUOUS_CALL // QTBUG-108805
|
||||
static_assert(bv == sv);
|
||||
static_assert(sv == bv);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
{
|
||||
|
|
@ -291,6 +321,10 @@ void tst_QByteArrayView::constExpr() const
|
|||
static_assert(bv.isNull());
|
||||
static_assert(bv.isEmpty());
|
||||
static_assert(bv.size() == 0);
|
||||
|
||||
constexpr std::string_view sv = bv;
|
||||
static_assert(sv.size() == 0);
|
||||
static_assert(sv.data() == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue