---
title: "QtConcurrent::mappedReduced使用仿函数(functor)"
author: "johnsmith9th"
date: "2022-04-11T12:38:40Z"
tags: []
categories: ["编程语言"]
slug: "qtconcurrent-mappedreduced-functor"
draft: false
lastmod: "2022-04-11T12:38:40Z"
id: 2530693
url: "https://johnsmith9th.iteye.com/blog/2530693"
---

参考https://stackoverflow.com/questions/17019954/specifying-reduce-functor-for-mappedreduce

有三个要点：

1\. MapFunctor必须定义result\_type类型: 例如 typedef QList&lt;int&gt; result\_type.

2\. ReduceFunctor的operator()函数的第一个参数即是最终的结果

3\. 调用blockingMappedReduced或者mappedReduced时需要显示指定模板参数的类型而不能依赖编译器推导。