diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 81af96b96bf..002c9bcda22 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -703,6 +703,15 @@ QDebug &QDebug::resetFormat() support streaming into QDebug. */ +/*! + \fn QDebug operator<<(QDebug stream, const std::list &list) + \relates QDebug + \since 5.7 + + Writes the contents of \a list to \a stream. \c T needs to + support streaming into QDebug. +*/ + /*! \fn QDebug operator<<(QDebug stream, const QVector &vector) \relates QDebug @@ -711,6 +720,15 @@ QDebug &QDebug::resetFormat() support streaming into QDebug. */ +/*! + \fn QDebug operator<<(QDebug stream, const std::vector &vector) + \relates QDebug + \since 5.7 + + Writes the contents of \a vector to \a stream. \c T needs to + support streaming into QDebug. +*/ + /*! \fn QDebug operator<<(QDebug stream, const QSet &set) \relates QDebug @@ -727,6 +745,24 @@ QDebug &QDebug::resetFormat() \c T need to support streaming into QDebug. */ +/*! + \fn QDebug operator<<(QDebug stream, const std::map &map) + \relates QDebug + \since 5.7 + + Writes the contents of \a map to \a stream. Both \c Key and + \c T need to support streaming into QDebug. +*/ + +/*! + \fn QDebug operator<<(QDebug stream, const std::multimap &map) + \relates QDebug + \since 5.7 + + Writes the contents of \a map to \a stream. Both \c Key and + \c T need to support streaming into QDebug. +*/ + /*! \fn QDebug operator<<(QDebug stream, const QHash &hash) \relates QDebug diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index b1a0396f35c..a01dd03a8a4 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -45,6 +45,12 @@ #include #include +// all these have already been included by various headers above, but don't rely on indirect includes: +#include +#include +#include +#include + QT_BEGIN_NAMESPACE @@ -192,28 +198,63 @@ inline QDebug &QDebug::operator=(const QDebug &other) return *this; } -template -inline QDebug operator<<(QDebug debug, const QList &list) +namespace QtPrivate { + +template +inline QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c) { const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << '('; - for (typename QList::size_type i = 0; i < list.count(); ++i) { - if (i) - debug << ", "; - debug << list.at(i); + debug.nospace() << which << '('; + typename SequentialContainer::const_iterator it = c.begin(), end = c.end(); + if (it != end) { + debug << *it; + ++it; + } + while (it != end) { + debug << ", " << *it; + ++it; } debug << ')'; debug.setAutoInsertSpaces(oldSetting); return debug.maybeSpace(); } +} // namespace QtPrivate + +template +inline QDebug operator<<(QDebug debug, const QList &list) +{ + return QtPrivate::printSequentialContainer(debug, "" /*for historical reasons*/, list); +} + template inline QDebug operator<<(QDebug debug, const QVector &vec) { - const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << "QVector"; - debug.setAutoInsertSpaces(oldSetting); - return operator<<(debug, vec.toList()); + return QtPrivate::printSequentialContainer(debug, "QVector", vec); +} + +template +inline QDebug operator<<(QDebug debug, const std::vector &vec) +{ + return QtPrivate::printSequentialContainer(debug, "std::vector", vec); +} + +template +inline QDebug operator<<(QDebug debug, const std::list &vec) +{ + return QtPrivate::printSequentialContainer(debug, "std::list", vec); +} + +template +inline QDebug operator<<(QDebug debug, const std::map &map) +{ + return QtPrivate::printSequentialContainer(debug, "std::map", map); // yes, sequential: *it is std::pair +} + +template +inline QDebug operator<<(QDebug debug, const std::multimap &map) +{ + return QtPrivate::printSequentialContainer(debug, "std::multimap", map); // yes, sequential: *it is std::pair } template @@ -252,13 +293,19 @@ inline QDebug operator<<(QDebug debug, const QPair &pair) return debug.maybeSpace(); } +template +inline QDebug operator<<(QDebug debug, const std::pair &pair) +{ + const bool oldSetting = debug.autoInsertSpaces(); + debug.nospace() << "std::pair(" << pair.first << ',' << pair.second << ')'; + debug.setAutoInsertSpaces(oldSetting); + return debug.maybeSpace(); +} + template inline QDebug operator<<(QDebug debug, const QSet &set) { - const bool oldSetting = debug.autoInsertSpaces(); - debug.nospace() << "QSet"; - debug.setAutoInsertSpaces(oldSetting); - return operator<<(debug, set.toList()); + return QtPrivate::printSequentialContainer(debug, "QSet", set); } template