On 11/10/11 05:44, Greg Ercolano wrote:
>
> Yaskhan writes:
>> sorry. c++0x
Being a pedant, I'll correct that to C++11. I've done the same with the 
title, as well. ;-)

>       I don't think anyone's tried using c++0x with fltk yet.
>
>       Assuming c++0x is back compatible with C++ (I don't know myself),
>       and that FLTK can compile under c++0x (or at least somehow
>       link with it), I guess the question is can a lambda be used
>       in place of a callback.
C++11 is supposed to be fully compatible with C++, so it should be 
back-compatible. All of FLTK currently compiles cleanly with -std=c++0x 
on gcc 4.4.5, too.

>       Probably; according to this document that I think describes
>       c++0x's implementation of Lambdas:
>       http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1968.pdf
>       ..which says:
>
> lambda functions, or closures, have many uses: as the arguments to 
> higher-order
> functions (such as std::for each in the context of C++), as callbacks for I/O
> functions or GUI objects, and so forth.
>

You might actually have a bit of difficulty using a lambda function as a 
callback, because to use some of their more powerful features (like 
taking variable callback data) I *think* the FLTK callback functions 
will have to be modified slightly. However, if I abuse the language for 
a little bit, something like this *should* work (read: code is 
completely untested and will not compile - it's an example and that is 
left as an exercise for the reader!):

my_button1("Button!")
my_button2.callback(<>(Fl_Widget* w) -> void {my_button1.label("No soup 
for you");});

You probably couldn't use "auto" as the return type here (nor decltype), 
as I think FLTK explicitly expects void, but you can theoretically do 
anything you want if you twist the function in the right way. Note that 
you can use it to call my_button1.label because of the magic of lambdas 
(they're translated into objects to make this possible)
While its not the empirical example of the use of a lambda function, 
this should be a start - if you get it to work in general (and/or with 
variable callback data), feel free to post it up to this newsgroup for 
all of us to see!


HTH
- Ben

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

Reply via email to