QDebug: simplify op<<(std::optional)

We don't need to enable nospace() if we stream but a single element
(nullopt). As a consequence, delay construction of the StateSaver
until we have determined that the optional is engaged.

Amends b7657ddccbe0a5ab1cdfc61ae6b7f0501dbfb24a.

Change-Id: Id974dff078cb989b92f84b63bf14956a2fba32b2
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit 25931bf2181706e1cba416b0530f07959182f074)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2024-10-24 14:35:32 +02:00 committed by Qt Cherry-pick Bot
parent a1dd67ebfc
commit e5e560c7fd

View File

@ -392,11 +392,10 @@ inline QDebugIfHasDebugStreamContainer<QMultiHash<Key, T>, Key, T> operator<<(QD
template <class T>
inline QDebugIfHasDebugStream<T> operator<<(QDebug debug, const std::optional<T> &opt)
{
const QDebugStateSaver saver(debug);
if (!opt)
debug.nospace() << std::nullopt;
else
debug.nospace() << "std::optional(" << *opt << ')';
return debug << std::nullopt;
const QDebugStateSaver saver(debug);
debug.nospace() << "std::optional(" << *opt << ')';
return debug;
}