[Interest] [External] Re: Confused about QtConcurrent mappedReduced() documentation

Sean Murphy Sean.M.Murphy at us.kbr.com
Mon Jun 6 14:57:51 CEST 2022

> Then you can detect the situation and initialise it to the right size on first use.

Yep, just making sure that was the intended/required solution, and that I wasn't
missing something. If possible, it would be nice for the documentation to be updated to
point out that detail for both QtConcurrent::mappedReduced() and

At minimum, updating these examples would be helpful:

As pointed out, the mappedReduced() example wouldn't work as described without
realizing that you somehow need to initialize the QImage object somehow.
The filteredReduced() one looks like it would actually work as described, but it would
still be nice to point out to the reader that the first call to your reduce function will
get a default constructed T object, which may or may not be what works with
whatever underlying T type requires.

For first-time users of the QtConcurrent API (like myself), more pointers in the
documentation are always better!

> But no, this is a limitation in the API. If we take the prototypical example of a
> reduction, std::accumulate, it does have an initial value:
> https://en.cppreference.com/w/cpp/algorithm/accumulate >

Is there any chance that in a future Qt release we could have additional versions
of mappedReduced() and filteredReduced() that allows the developer to pass in
a pre-intialized T& object? I haven't looked at the underlying Qt code for it, but
my assumption is the only risk of doing this is that the *reduced() functions couldn't
guarantee that I wasn't messing around with that same T& object in another thread,
at the time the reduce function are trying to use it. But I'd think providing the
functionality to pass one in, along with the documentation warning the developer that
they shouldn't attempt to access the T& they passed in until the *reduced() operation has
finished would be sufficient?

This e-mail, including any attached files, may contain confidential information, privileged information and/or trade secrets for the sole use of the intended recipient. Any review, use, distribution, or disclosure by others is strictly prohibited. If you are not the intended recipient (or authorized to receive information for the intended recipient), please contact the sender by reply e-mail and delete all copies of this message.

More information about the Interest mailing list