Ivan Solovev 3978f3d5ec Warn if QFuture::then() is called for a QFuture with multiple results
QFuture is tricky in the sense that it can store multiple results.
The users might write the code like:

  QList<int> values{1, 2, 3};
  auto f = QtConcurrent::mapped(values, func)
              .then([](auto val) { otherFunc(val); });

with the expectation that the lambda will be called on each mapped
value of the original input container.
However, that is not true. QtConcurrent::mapped() returns a QFuture
which has multiple results, and in this case only the first result will
be passed to the then() continuation.

We cannot detect this problem at compile-time, because we do not know
how many results will the QFuture hold. So, add at least a runtime
warning.

The warning is added in a new logging category, so that the users who
really need this behavior can disable it. The warning is implemented
as an exported out-of-line method for two reasons:
* To avoid code duplication for each template parameter of
  CompactContinuation.
* To avoid exposing a Qt-specific logging category into a public header.

Such design, however, prevents us from cherry-picking the change to
older branches.

Fixes: QTBUG-133522
Change-Id: I3344b5228b50e9c9d68d0c57961bbc969f566bb9
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-03-24 11:39:34 +01:00
..