summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-07-06 13:08:40 +0200
committerLars Knoll <lars.knoll@qt.io>2020-08-15 14:43:23 +0200
commit8ad9e81694fda39fbecebb9f97491004e9ac8c41 (patch)
treeb5a5e9bc6bd95dea730cb466627e8a225bd1ab94 /src/corelib/global
parent6c36fd8af7e873defa3843f49848a14980561647 (diff)
Constrain the debug stream operators for containers
Check that we can successfully instantiate the debug stream operator for a container before we actually try. This is required so we can automate registration of debug stream operators with QMetaType. Change-Id: I3943e7a443751d250c33b2ca1b9cf29207cfe6c4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qtypeinfo.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/global/qtypeinfo.h b/src/corelib/global/qtypeinfo.h
index be21526339..2f7bb414b5 100644
--- a/src/corelib/global/qtypeinfo.h
+++ b/src/corelib/global/qtypeinfo.h
@@ -48,6 +48,8 @@
QT_BEGIN_NAMESPACE
+class QDebug;
+
/*
QTypeInfo - type trait functionality
*/
@@ -445,6 +447,23 @@ using compare_eq_result = std::enable_if_t<std::conjunction_v<QTypeTraits::has_o
template <typename ...T>
using compare_lt_result = std::enable_if_t<std::conjunction_v<QTypeTraits::has_operator_less_than<T>...>, bool>;
+namespace detail {
+
+template<typename T>
+const T const_value();
+template<typename T>
+T &reference();
+
+}
+
+template <typename Stream, typename, typename = void>
+struct has_ostream_operator : std::false_type {};
+template <typename Stream, typename T>
+struct has_ostream_operator<Stream, T, std::void_t<decltype(detail::reference<Stream>() << detail::const_value<T>())>>
+ : std::true_type {};
+template <typename Stream, typename T>
+constexpr bool has_ostream_operator_v = has_ostream_operator<Stream, T>::value;
+
}