From b7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 20 Nov 2023 20:46:23 +0100 Subject: qDebug: add support for std::optional and std::nullopt_t [ChangeLog][QtCore][QDebug] Added support for std::optional and std::nullopt_t Change-Id: I1e6196adb408401cae8776cd0c60af294a39a83f Reviewed-by: Thiago Macieira Reviewed-by: Marc Mutz Reviewed-by: Volker Hilsheimer --- src/corelib/io/qdebug.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/corelib/io/qdebug.h') diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index f5a35236e1a..770f4fac9a8 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -126,6 +126,7 @@ public: inline QDebug &operator<<(QByteArrayView t) { putByteArray(t.constData(), t.size(), ContainsBinary); return maybeSpace(); } inline QDebug &operator<<(const void * t) { stream->ts << t; return maybeSpace(); } inline QDebug &operator<<(std::nullptr_t) { stream->ts << "(nullptr)"; return maybeSpace(); } + inline QDebug &operator<<(std::nullopt_t) { stream->ts << "nullopt"; return maybeSpace(); } inline QDebug &operator<<(QTextStreamFunction f) { stream->ts << f; return *this; @@ -361,6 +362,17 @@ inline QDebugIfHasDebugStreamContainer, Key, T> operator<<(QD return QtPrivate::printAssociativeContainer(debug, "QMultiHash", hash); } +template +inline QDebugIfHasDebugStream operator<<(QDebug debug, const std::optional &opt) +{ + const QDebugStateSaver saver(debug); + if (!opt) + debug.nospace() << std::nullopt; + else + debug.nospace() << "std::optional(" << *opt << ')'; + return debug; +} + template inline QDebugIfHasDebugStream operator<<(QDebug debug, const std::pair &pair) { -- cgit v1.2.3