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.

Pick-to: 6.8
Change-Id: Id974dff078cb989b92f84b63bf14956a2fba32b2
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Marc Mutz 2024-10-24 14:35:32 +02:00
parent dd672edd15
commit 25931bf218

View File

@ -424,11 +424,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;
}