From the QtConcurrent documentation:
QByteArray bytearray = "hello world";
QFuture<QList<QByteArray> > future = QtConcurrent::run(bytearray, &QByteArray::split), ',');
...
QList<QByteArray> result = future.result();
The code snippet above appears to be binding a function in a similar way to std::tr1::bind (std::bind for > C++11). That is to say it’s taking a non-static member function (QByteArray::split()) and (at some point later) calling it on the specific instance of the object of which it’s a member (which we’ve supplied as bytearray).
How does Qt achieve this? Is it using std::tr1::bind or boost::bind somewhere behind the scenes?
The documentation does also refer to a case where you would use std::tr1 or boost instead, but I don’t fully understand what it means by a bound function in that context. Is the situation above in fact different/more specialised/simpler than other situations where you might otherwise use tr1 or boost?
I’ve tried to make my way through the source but am getting lost very quickly!
I’m going to attempt a self answer, as the existing answers (many thanks to @Mike Brown and @skyhisi) lay the groundwork but don’t address this specific case…
From the source:
QtConcurrent::run(…) :
SelectStoredMemberFunctionCall0:
VoidStoredMemberFunctionCall0:
Given the above, I can see that Qt stores a pointer-to-member-function in the normal way, but by dressing it up in templates which would otherwise go unnoticed, the illusion of generic-ness is created.
The type of
VoidStoredMemberFunctionCall0::objectas well as the signature ofVoidStoredMemberFunctionCall0::fnare all specified above in the arguments passed toQtConcurrent::run.I wasn’t aware that this ‘implicit’ templatization was even possible, to be honest. Would anybody be able to recommend further reading?