From 12b41c3332612eb26b7b8598c0a94a4f0d709787 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 21 Oct 2024 14:56:01 +0200 Subject: QDebug: add streaming operators for std::tuple Unlike the existing one for std::pair, make the operator SCARY, using the newly-added StreamTypeErased type-erasure (added in 5cdd1f594d26e1d4f84b00741be1ab7231458512). [ChangeLog][QtCore][QDebug] Can now stream std::tuple. Change-Id: I46670ac32eaee7f0ea5f4543ebcf59e19b394166 Reviewed-by: Ivan Solovev --- src/corelib/io/qdebug.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/corelib/io/qdebug.cpp') diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 598355e4296..39eccd889cf 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -1086,6 +1086,33 @@ QByteArray QDebug::toBytesImpl(StreamTypeErased s, const void *obj) return result; } +/*! + \internal + \since 6.9 + + Outputs a heterogeneous product type (pair, tuple, or anything that + implements the Tuple Protocol). The class name is described by "\a ns + \c{::} \a what", while the addresses of the \a n elements are stored in the + array \a data. The formatters are stored in the array \a ops. + + If \a ns is empty, only \a what is used. +*/ +QDebug &QDebug::putTupleLikeImplImpl(const char *ns, const char *what, + size_t n, StreamTypeErased *ops, const void **data) +{ + const QDebugStateSaver saver(*this); + nospace(); + if (ns && *ns) + *this << ns << "::"; + *this << what << '('; + while (n--) { + (*ops++)(*this, *data++); + if (n) + *this << ", "; + } + return *this << ')'; +} + /*! \fn template QDebug operator<<(QDebug debug, const QList &list) \relates QDebug @@ -1179,6 +1206,14 @@ QByteArray QDebug::toBytesImpl(StreamTypeErased s, const void *obj) \c T need to support streaming into QDebug. */ +/*! + \fn template > QDebug &QDebug::operator<<(const std::tuple &tuple) + \since 6.9 + + Writes the contents of \a tuple to the stream. All \c Ts... need to support + streaming into QDebug. +*/ + /*! \fn template QDebug operator<<(QDebug debug, const std::pair &pair) \relates QDebug -- cgit v1.2.3