ZFFramework
Loading...
Searching...
No Matches
Lambda with pure C++03

thanks to powerful generic ZFCallback, we are able to implement lambda feature with pure C++03
example:

ZFUIRect refCapture = ZFUIRectZero();
ZFUIRect valueCapture = ZFUIRectZero();
ZFLISTENER_2(onClick
, ZFUIRect &, refCapture
, ZFUIRect, valueCapture
) {
refCapture.width = 999;
valueCapture.width = 999;
btn->observerAdd(ZFUIButton::EventButtonOnClick(), onClick);
zfLogTrim() << "before invoke: " << refCapture << valueCapture;
btn->simulateClick();
zfLogTrim() << "after invoke: " << refCapture << valueCapture;
// output:
// before invoke: (0, 0, 0, 0) (0, 0, 0, 0)
// after invoke: (0, 0, 999, 0) (0, 0, 0, 0)
#define ZFLISTENER_2(name, CaptureParam0, capture0, CaptureParam1, capture1)
see ZFLISTENER
Definition ZFListenerDeclare.h:79
#define ZFLISTENER_END()
see ZFLISTENER
Definition ZFListenerDeclare.h:17
#define zfLogTrim(...)
see zfLog
Definition ZFLog.h:66
ZFUIRect const & ZFUIRectZero()
(0, 0, 0, 0)
Definition ZFUITypeDef.h:639
abstract button
Definition ZFUIButton.h:41
2D rectangle
Definition ZFUITypeDef.h:612
zffloat width
width
Definition ZFUITypeDef.h:616
util class to alloc and hold ZFObject type
Definition ZFObjectAutoPtr.h:163


as you may noticed, we can capture vars outside of the lambda function
you should take care of the life circle of the captured vars, though