Re: Delegates ,smart pointers and GUI
On 30 Apr., 15:16, Phlip <phlip2...@gmail.com> wrote:
KjellKod wrote:
Something very similar as 'delegates' are in fact commonly used in C++
(GUI) frameworks.
Check out signals by
Boost (http://www.boost.org/doc/libs/1_38_0/doc/html/signals.html)
and Qt (http://doc.trolltech.com/4.5/signalsandslots.html)
Signals and slots are not "in C++". Trolltech provides them by adding two new
keywords to C++. You can't do what they did without their language extension.
It's my understanding that a similar feature can be more or less
emulated with C++ language features. IIRC, Trolltech didn't do it that
way because they started development early and C++ compilers were not
very mature w.r.t. templates back then.
I'm not much of a GUI programmer but I did check out gtkmm a little
bit. They also have signals and slots but they're implemented as a C++
library.
The only experience with GUI programming I have is with Java/Swing.
The talk about closures reminded of the need to write something like
SwingUtilities.invokeLater(new Runnable(){
public void run() {
// do something
}
});
in Java if you're in another thread and want an action to be performed
in Swing's event loop thread. In C++0x you'd be able to do something
similar:
// called from event loop thread as result of
// a user action, for example
void foo::on_click() {
MyGuiFramework::perform_async(
[] { calculations(); }, // async job
[this] { this->ready(); } // when done
);
}
// called from event loop thread
// (after calculations are complete)
void foo::ready() {
// ...
}
where most of the magic is hidden behind the fictional
"MyGuiFramework::perform_async". This is just one idea that comes to
mind. ;-)
Cheers!
SG