summaryrefslogtreecommitdiffstats
path: root/src/corelib/serialization
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-05-20 15:20:07 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-31 22:57:49 +0200
commit2c9529e158fc589c48e6b1fb61dca2133e33ac4d (patch)
treee9429715ab339d95c2ba9456bf39a894e8b41539 /src/corelib/serialization
parentf0ae973244026ca5382f05630bd799b44154d224 (diff)
Long live Q{Any,Utf8}StringView!
We need to add these two classes at the same time, because QAnyStringView makes all QUtf8StringView relational operators moot. We might want to add some later, esp. for UTF-8/UTf-8 comparisons, to avoid the pessimization that we can't early-out on size() mismatch in QAnyStringView equality operators, but that's an optimization, not a correctness issue, and can be fixed in a source-compatible way even after Qt 6 is released. To deal with the char8_t problem in C++20, make QUtf8StringView a class template out of which two UTF-8 views can be instantiated: the Qt 7 version, which depends on C++20 char8_t as value_type, and the Qt 6 version where value_type is a char. Use inline namespaces to map the QUtf8StringView identifier to one or the other, depending on the C++ version used to compile the user code. The inline namespace names must needs be a bit ugly, as their inline'ness depends on __cpp_char8_t. If we simply used q_v1/q_v2 we'd be blocking these names for Qt inline namespaces forever, because it's likely that inline'ness of other users of inline namespaces in Qt depends on things other than __cpp_char8_t. While inline'ness of namespaces is, theoretically speaking, a compile-time-only property, at least Clang warns about mixed use of inline on a given namespace, so we need to bite the bullet here. This is also the reason for the QT_BEGIN_..._NAMESPACE macros: GCC is ok with the first declaration making a namespace inline, while Clang warns upon re-opening an inline namespace as a non-inline one. [ChangeLog][QtCore][QUtf8StringView] New class. [ChangeLog][QtCore][QAnyStringView] New class. Change-Id: Ia7179760fca0e0b67d52f5accb0a62e389b17913 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r--src/corelib/serialization/qxmlstream_p.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/corelib/serialization/qxmlstream_p.h b/src/corelib/serialization/qxmlstream_p.h
index 0759e92ce7..21229a949e 100644
--- a/src/corelib/serialization/qxmlstream_p.h
+++ b/src/corelib/serialization/qxmlstream_p.h
@@ -94,6 +94,34 @@ public:
bool isEmpty() const { return m_size == 0; }
bool isNull() const { return !m_string; }
QString toString() const { return view().toString(); }
+
+#define MAKE_OP(op) \
+ friend auto operator op(const XmlStringRef &lhs, const XmlStringRef &rhs) noexcept { return lhs.view() op rhs.view(); } \
+ /*end*/
+ MAKE_OP(==)
+ MAKE_OP(!=)
+ MAKE_OP(<=)
+ MAKE_OP(>=)
+ MAKE_OP(<)
+ MAKE_OP(>)
+#ifdef __cpp_impl_three_way_comparison
+ MAKE_OP(<=>)
+#endif
+#undef MAKE_OP
+#define MAKE_OP(op) \
+ friend auto operator op(const XmlStringRef &lhs, QStringView rhs) noexcept { return lhs.view() op rhs; } \
+ friend auto operator op(QStringView lhs, const XmlStringRef &rhs) noexcept { return lhs op rhs.view(); } \
+ /*end*/
+ MAKE_OP(==)
+ MAKE_OP(!=)
+ MAKE_OP(<=)
+ MAKE_OP(>=)
+ MAKE_OP(<)
+ MAKE_OP(>)
+#ifdef __cpp_impl_three_way_comparison
+ MAKE_OP(<=>)
+#endif
+#undef MAKE_OP
};
}