On 14/10/11 21:37, Piotr Beling [qwak] wrote:
> W dniu 11.10.2011 05:19, Ben Stott pisze:
>
>> my_button2->callback( [this] () { this->my_button1->label("xxx");} ); // I 
>> haven't specified the return type here; it will default to void. You could 
>> just as easily use "[this] () ->   void {...}"
> This probably will not work, because
> [this] () { this->my_button1->label("xxx");}
> is not a function (it is an object with operator(), and probably with
> field to store "this" pointer).

Hmm, this is true, however by overloading a class's operator(), it 
essentially acts like a function any way - and since all callbacks are 
cast to (void*)(), this shouldn't have any impact. Like I also 
mentioned, however, chances are you don't need the [this] as it _should_ 
be captured anyway, though I was struggling to recall whether or not it 
was a pointer to a copy of the original object or a pointer to the 
original object itself.

> As I remember, only lambdas with empty [] can be compiled to pure C
> function and GCC do this, but VS not.
> So, currently, under VS lambdas will newer work with fltk.

Under VS, what (recent) feature of C/++ *does* work? ;-)
I suppose at this stage, anything to do with the C++11 standard should 
probably be qualified with the "YMMV" tag, as far as FLTK goes. Support 
will differ based on compiler vendors and nobody has really strenuously 
tested any of the new features with it. If it works, hey, awesome. If 
not, well, that's probably to be expected.

> Maybe it is good idea to use some signal/slot system in new fltk3 to
> allow using complex lambdas (and avoid cast to/from void*)?
> http://stackoverflow.com/questions/359928/which-c-signals-slots-library-should-i-choose
>

If anything, it'll be easier to use std::function - and if it really 
needs to happen this is more likely the option that would be looked at, 
as it does not require the use of any extra external libraries. The 
Callback typedef would only have to be modified to std::function<void 
(Widget*, void*)>, and everything should continue to work with the added 
bonus of lambdas now working, amongst other things.

Regards,
Ben

_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to