QDebug: add streaming operators for std::multiset
The stream insertion operator for QDebug is not overloaded to handle std::multiset Overload the stream insertion operator for QDebug to handle std::multiset [ChangeLog][QtCore][QDebug] Added support for std::multiset. Fixes: QTBUG-131428 Change-Id: I7e3b721afe88d68c99c44c0d7cc9ee7711c169c8 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
a1e6fed449
commit
850d4895be
@ -1188,6 +1188,15 @@ QDebug &QDebug::putTupleLikeImplImpl(const char *ns, const char *what,
|
||||
\c T need to support streaming into QDebug.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn template <typename Key, typename Compare, typename Alloc> QDebug operator<<(QDebug debug, const std::multiset<Key, Compare, Alloc> &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 <typename Key, typename Compare, typename Alloc> QDebug operator<<(QDebug debug, const std::set<Key, Compare, Alloc> &set)
|
||||
\relates QDebug
|
||||
|
@ -439,6 +439,12 @@ inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug, const std::multim
|
||||
return QtPrivate::printSequentialContainer(std::move(debug), "std::multimap", map); // yes, sequential: *it is std::pair
|
||||
}
|
||||
|
||||
template <typename Key, typename Compare, typename Alloc>
|
||||
inline QDebug operator<<(QDebug debug, const std::multiset<Key, Compare, Alloc> &multiset)
|
||||
{
|
||||
return QtPrivate::printSequentialContainer(std::move(debug), "std::multiset", multiset);
|
||||
}
|
||||
|
||||
template <typename Key, typename Compare, typename Alloc>
|
||||
inline QDebug operator<<(QDebug debug, const std::set<Key, Compare, Alloc>& set)
|
||||
{
|
||||
|
@ -38,6 +38,7 @@ static_assert(QTypeTraits::has_ostream_operator_v<QDebug, int>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, QMetaType>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, QList<int>>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, QMap<int, QString>>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, std::multiset<int>>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, std::set<int>>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, std::tuple<int, QString, QMap<int, QString>>>);
|
||||
static_assert(QTypeTraits::has_ostream_operator_v<QDebug, std::unordered_map<int, QString>>);
|
||||
@ -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<int> 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<std::string>{"apple", "banana", "cherry", "banana", "apple"};
|
||||
QCOMPARE(s_msg, "std::multiset(\"apple\", \"apple\", \"banana\", \"banana\", \"cherry\")"_L1);
|
||||
|
||||
qDebug() << std::multiset<int>{};
|
||||
QCOMPARE(s_msg, "std::multiset()"_L1);
|
||||
}
|
||||
|
||||
void tst_QDebug::qDebugStdPair() const
|
||||
{
|
||||
QByteArray file, function;
|
||||
|
Loading…
x
Reference in New Issue
Block a user