QtConcurrent-BlockingMapped-Other-Object-Member-Function-Operator: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
Demonstrates how to pass each object in the container to a member function of different class instance. You can alternatively do this using "boost::bind":http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Bind
Demonstrates how to pass each object in the container to a member function of different class instance. You can alternatively do this using "boost::bind":http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Bind


<code><br />#include <QtConcurrentMap><br />#include <QVector>
<code>
#include <QtConcurrentMap>
#include <QVector>


#include <boost/bind.hpp>
#include <boost/bind.hpp>
Line 9: Line 11:
class Object{};
class Object{};


class MyClass<br />{<br />public:<br /> float operator()(const Object&amp;amp; object) { return 1.0f;}<br /> typedef float result_type;<br />};
class MyClass
{
public:
float operator()(const Object&amp;amp; object) { return 1.0f;}
typedef float result_type;
};


int main()<br />{<br /> QVector&amp;amp;lt;Object&amp;amp;gt; v;<br /> Object a;<br /> v.push_back(a);
int main()
{
QVector&amp;amp;lt;Object&amp;amp;gt; v;
Object a;
v.push_back(a);


MyClass myClass;
MyClass myClass;
Line 17: Line 28:
QVector<float> result = QtConcurrent::blockingMapped<QVector<float> >(v.begin(), v.end(), myClass);
QVector<float> result = QtConcurrent::blockingMapped<QVector<float> >(v.begin(), v.end(), myClass);


std::cout << result[0] << std::endl;<br /> return 0;<br />}
std::cout << result[0] << std::endl;
return 0;
}

Revision as of 11:32, 25 February 2015

Demonstrates how to pass each object in the container to a member function of different class instance. You can alternatively do this using "boost::bind":http://developer.qt.nokia.com/wiki/QtConcurrent-BlockingMapped-Other-Object-Member-Function-Bind

  1. include <QtConcurrentMap>
  2. include <QVector>
  1. include <boost/bind.hpp>
  1. include <iostream>

class Object{};

class MyClass { public:

float operator()(const Object&amp; object) { return 1.0f;}
typedef float result_type;

};

int main() {

QVector&amp;lt;Object&amp;gt; v;
Object a;
v.push_back(a);

MyClass myClass;

QVector<float> result = QtConcurrent::blockingMapped<QVector<float> >(v.begin(), v.end(), myClass);

std::cout << result[0] << std::endl;

return 0;

}