On Mon, Aug 9, 2010 at 4:45 AM, Koen Deforche <[email protected]> wrote:
> Hey Volker,
>
> 2010/8/9 Volker <[email protected]>:
>> Hi koen,
>>
>> why not call the macro WSLOT instead and add a define for backwards
>> compatibilty. As everything else in Wt is prefixed with W.
>
> I would rather not break what currently works (SLOT) for users who are
> not using Qt.
>
> That means that as a Wt/Qt intermixer, you would need to take action
> (setting a define that disables or renames the SLOT macro).
>
> The simplest solution is to remove the SLOT define. If the Qt user
> prefers a macro, he can #define one for himself like this:
>
> #define WSLOT(a, b) a, &b
>
> Ultimately, I prefer to move on and forget about the SLOT macro
> entirely. With c++0x come lambda's and we already have boost::bind()
> that is convenient for passing additional information to the slot
> method. These two uses add good functionality and are not compatible
> with a SLOT macro anyway.
>
> ( see also my recent blog post about c++0x lambda's and Wt :
> http://www.webtoolkit.eu/wt#/blog/2010/08/06/wt_and_c__0x/ )
I really do not like C++0x lambda's, they are restricted and
monomorphic and so forth. Look at this example from your blog post:
> using namespace Wt;
>
> WPushButton *button = new WPushButton("Click me", this);
>
> button->clicked().connect([=] (const WMouseEvent& e)
> {
> button->setText("Thank you!");
> });
Now compare that to a Boost.Phoenix version:
> using namespace Wt;
> using namespace boost.phoenix;
>
> WPushButton *button = new WPushButton("Click me", this);
>
> button->clicked().connect(bind(&WPushButton::setText, button, "Thank you!"));
Although if you were to *properly* phoenixe'ize that last line, it
would look like this:
> button->clicked().connect(setText(button, "Thank you!")); // maybe _setText
> or setText_ or so to prevent ambiguity, and this will work with anything that
> has a setText member, polymorphic or not
Although this is not the best example of lambda's as it can also be
performed by boost::bind or so, a better example is this (using C++0x
lambda's):
> using namespace Wt;
> using namespace boost.phoenix;
>
> WPushButton *button = new WPushButton("Click me", this);
> bool someStateThatPersists = false; // might be true later, might not...
> this persists though
>
> button->clicked().connect([&someStateThatPersists, button] (const
> WMouseEvent& e) // not sure the syntax is perfectly correct in the [] part...)
> {
> if(someStateThatPersists)
> {
> button->setText("Thank you!");
> }
> else
> {
> button->setText("Why am I still false?!? Setting myself to true for
> next time");
> someStateThatPersists = true;
> }
> });
Or in a proper phoenix way:
> using namespace Wt;
> using namespace boost.phoenix;
>
> WPushButton *button = new WPushButton("Click me", this);
> bool someStateThatPersists = false; // might be true later, might not...
> this persists though
>
> button->clicked().connect(
> if_(ref(someStateThatPersists))
> [
> setText(button, "ThankYou!") // if button does not compile, depending
> on how you made setText, you might need to replace it with val(button)
> instead, properly made though, this should work.
> ]
> .else
> [
> setText(button, "Why am I still false?!? Setting myself to true for
> next time"),
> ref(someStateThatPersists)=true
> ]);
And yes, that is proper C++, that is phoenix, completely self
contained, needs to signature, it ignores any passed in parameters
that it does not use, and it is fully capable of inlining (unlike
C++0x lambda's in current compilers). You can completely simplify and
coalesce phoenix functions to simplify the syntax and add abilities, a
Wt made using phoenix composition (especially the new capabilities in
phoenix3) would be truly powerful while being more simple.
Do note, phoenix works fine in Wt, I use it just like the above. :p
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest