PDA

View Full Version : Reduce Functor in QtConcurrent::mappedReduced



ksrarc
12th June 2009, 18:22
Hi,

I want to use QtConcurrent::mappedReduced with only Functors but compiler says:


error: no matching function for call to ‘mappedReduced(const int*, const int*, MapS, ReduceS)’

the map functor works but the reducer not.
the code is:


struct MapS
{
typedef int result_type;

int operator()( int v )
{
return v;
}
};

struct ReduceS
{
typedef int result_type;
void operator()( int & r, const int & v )
{
r+=v;
}
};

int main( int argc, char ** argv )
{
QVector<int> vector( 1024, 1 );
for( int i = 0; i < vector.count(); ++i )
vector[i]=i+1;

qDebug() << QtConcurrent::mappedReduced( vector.constBegin(), vector.constEnd(), MapS(), ReduceS() );

return 0;
}

so, is possible to use Functor Object as reduce functor? and how it must be defined?

Thanks.

caduel
12th June 2009, 20:22
try const int &r for the reducer's first arg?