diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 1fb2addc9ed..fc70e066f78 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -1258,10 +1258,9 @@ QDebug &QDebug::putTupleLikeImplImpl(const char *ns, const char *what, /*! \since 6.7 - \fn template QDebug operator<<(QDebug debug, const std::optional &opt) - \relates QDebug + \fn template > QDebug::operator<<(const std::optional &opt) - Writes the contents of \a opt (or \c nullopt if not set) to \a debug. + Writes the contents of \a opt (or \c nullopt if not set) to this stream. \c T needs to support streaming into QDebug. */ diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index 7dc6155259e..02628bc5cd6 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -299,6 +299,16 @@ public: return putTupleLike("std", "tuple", t); } + template = true> + QDebug &operator<<(const std::optional &o) + { + if (!o) + return *this << std::nullopt; + StreamTypeErased s = &streamTypeErased>; + const void *d = std::addressof(*o); + return putTupleLikeImplImpl("std", "optional", 1, &s, &d); + } + private: template using if_ordering_type = std::enable_if_t, bool>; @@ -490,16 +500,6 @@ inline QDebugIfHasDebugStreamContainer, Key, T> operator<<(QD return QtPrivate::printAssociativeContainer(std::move(debug), "QMultiHash", hash); } -template -inline QDebugIfHasDebugStream operator<<(QDebug debug, const std::optional &opt) -{ - if (!opt) - return debug << std::nullopt; - const QDebugStateSaver saver(debug); - debug.nospace() << "std::optional(" << *opt << ')'; - return debug; -} - template inline QDebugIfHasDebugStream operator<<(QDebug debug, const std::pair &pair) {