diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 5c80cb01091..9b64be67ceb 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -1188,6 +1188,15 @@ QDebug &QDebug::putTupleLikeImplImpl(const char *ns, const char *what, \c T need to support streaming into QDebug. */ +/*! + \fn template QDebug operator<<(QDebug debug, const std::multiset &multiset) + \relates QDebug + \since 6.9 + + Writes the contents of \a multiset to \a debug. The \c Key type + needs to support streaming into QDebug. +*/ + /*! \fn template QDebug operator<<(QDebug debug, const std::set &set) \relates QDebug diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h index b7b34f654dd..f12b7dba13d 100644 --- a/src/corelib/io/qdebug.h +++ b/src/corelib/io/qdebug.h @@ -439,6 +439,12 @@ inline QDebugIfHasDebugStream operator<<(QDebug debug, const std::multim return QtPrivate::printSequentialContainer(std::move(debug), "std::multimap", map); // yes, sequential: *it is std::pair } +template +inline QDebug operator<<(QDebug debug, const std::multiset &multiset) +{ + return QtPrivate::printSequentialContainer(std::move(debug), "std::multiset", multiset); +} + template inline QDebug operator<<(QDebug debug, const std::set& set) { diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index b2fd65fff5d..3b50636dfdd 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -38,6 +38,7 @@ static_assert(QTypeTraits::has_ostream_operator_v); static_assert(QTypeTraits::has_ostream_operator_v); static_assert(QTypeTraits::has_ostream_operator_v>); static_assert(QTypeTraits::has_ostream_operator_v>); +static_assert(QTypeTraits::has_ostream_operator_v>); static_assert(QTypeTraits::has_ostream_operator_v>); static_assert(QTypeTraits::has_ostream_operator_v>>); static_assert(QTypeTraits::has_ostream_operator_v>); @@ -88,6 +89,7 @@ private slots: void qDebugQStringView() const; void qDebugQUtf8StringView() const; void qDebugQLatin1String() const; + void qDebugStdMultiSet() const; void qDebugStdPair() const; void qDebugStdSet() const; void qDebugStdTuple() const; @@ -702,6 +704,33 @@ void tst_QDebug::qDebugQLatin1String() const QCOMPARE(s_msg, QString("\"\\nSm\\u00F8rg\\u00E5sbord\\\\\"")); } +void tst_QDebug::qDebugStdMultiSet() const +{ + QByteArray file, function; + int line = 0; + MessageHandlerSetter mhs(myMessageHandler); + + { + QDebug d = qDebug(); + std::multiset multiset{1, 2, 3, 2, 1}; + d.nospace().noquote() << multiset; + } +#ifndef QT_NO_MESSAGELOGCONTEXT + file = __FILE__; line = __LINE__ - 5; function = Q_FUNC_INFO; +#endif + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, "std::multiset(1, 1, 2, 2, 3)"_L1); + QCOMPARE(s_file, file); + QCOMPARE(s_line, line); + QCOMPARE(s_function, function); + + qDebug() << std::multiset{"apple", "banana", "cherry", "banana", "apple"}; + QCOMPARE(s_msg, "std::multiset(\"apple\", \"apple\", \"banana\", \"banana\", \"cherry\")"_L1); + + qDebug() << std::multiset{}; + QCOMPARE(s_msg, "std::multiset()"_L1); +} + void tst_QDebug::qDebugStdPair() const { QByteArray file, function;