diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2024-10-21 14:56:01 +0200 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2024-11-05 18:53:03 +0000 |
| commit | 12b41c3332612eb26b7b8598c0a94a4f0d709787 (patch) | |
| tree | abe7401ace3f4afacb92a00d1b6d3cdf142f2081 /src/corelib/io/qdebug.cpp | |
| parent | 2c8302682ec45abf9688380021e915e216d9ae3d (diff) | |
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 <ivan.solovev@qt.io>
Diffstat (limited to 'src/corelib/io/qdebug.cpp')
| -rw-r--r-- | src/corelib/io/qdebug.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
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 @@ -1087,6 +1087,33 @@ QByteArray QDebug::toBytesImpl(StreamTypeErased s, const void *obj) } /*! + \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 <class T> QDebug operator<<(QDebug debug, const QList<T> &list) \relates QDebug @@ -1180,6 +1207,14 @@ QByteArray QDebug::toBytesImpl(StreamTypeErased s, const void *obj) */ /*! + \fn template <class...Ts, QDebug::if_streamable<Ts...>> QDebug &QDebug::operator<<(const std::tuple<Ts...> &tuple) + \since 6.9 + + Writes the contents of \a tuple to the stream. All \c Ts... need to support + streaming into QDebug. +*/ + +/*! \fn template <class T1, class T2> QDebug operator<<(QDebug debug, const std::pair<T1, T2> &pair) \relates QDebug |
