Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QtConcurrent::mappedReduced without mapped
Forum Updated to NodeBB v4.3 + New Features

QtConcurrent::mappedReduced without mapped

Scheduled Pinned Locked Moved Unsolved Qt 6
3 Posts 2 Posters 381 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Roman.PodymovR Offline
    Roman.PodymovR Offline
    Roman.Podymov
    wrote on last edited by
    #1

    I already asked this question here, but there is still no answer.
    Consider the following code (Qt 6.0.3, C++17):

    const QVector<int> arr = {1, 2, 3, 4, 5};
    auto future = QtConcurrent::mappedReduced<int>(arr, [](auto item) {
        return item;
    }, [](int& result, auto item) {
        result += item;
    });
    

    As you can see the first lambda expression passed to QtConcurrent::mappedReduced looks unnecessary. That's why I want to find something like QtConcurrent::reduced in Qt 6. Or how can I refactor this code to use only 1 lambda expression?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You can use std::accumulate.

      The goal of QtConcurrent mappedReduce is the apply an operation on all the items of container in a concurrent fashion and once done do the reduction.

      In your case there's nothing to be done but the sum of the items so there's no need for mappedReduce.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Roman.PodymovR Offline
        Roman.PodymovR Offline
        Roman.Podymov
        wrote on last edited by
        #3

        Hello @SGaist
        Thank you for your message. We can continue here.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved