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 thoughbutton->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 thoughbutton->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
*Please* fix the blog comment parser? It is eating all my space and is not working!
There you go. I've implemented <code> tags for inserting a block of code (although it currently isn't syntax highlighted).