FLTK logo

Re: [fltk/fltk] Add lambdas with captures as callback option. (PR #1597)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.issues  ]
 
[ Previous Message ] [ New Message | Reply ] [ Next Message ]

Re: [fltk/fltk] Add lambdas with captures as callback option. (PR #1597) Matthias Melcher 04:26 Sep 07  
 
MatthiasWM left a comment (fltk/fltk#1597)

This would mean to also commit PR #1600 which is not yet complete and which is reported to require an undesired "templatification". I'm not familiar enough with advanced C++-11 features such as std::forward, std::move, std::function to really evaluate this question.

Thanks, Manolo. #1600 was a test with all what C++11 has to offer. Instead, I'd like to rewrite this with a little less templates and cleaner interface.

std::foward lat's you map one call onto another by forwarding all or part of the function parameters. We have callback(()(Fl_WIdget,void*)), callback(()(Fl_WIdget,long)), callback(std::function<void()>), etc. . By writing Fl::add_timeout(double, std::forward<...>...), C++ automatically writes l::add_timeout(double, ()(Fl_WIdget,void*)) etc. for us.

I made the callback interface not movable and not copiable on purpose to avoid all the issues that arise from managing void*. So no std::move needed. Fl_Widget is not movable or copiable anyway.

std::function is very similar to what the callback macros do: it creates a struct that stores the captured values (to ones between [ and ]), and create the same static callback function that FLTK generally uses. It just does it in the background, keeping code readable. Lambdas are meant to be short (Python lambdas are limited to one function) and just call something more complex in a flexible and readable way.

—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <fltk/fltk/pull/1597/c5569921584@github.com>

[ Direct Link to Message ]
 
     
[ Previous Message ] [ New Message | Reply ] [ Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.