Hasty Briefsbeta

Bilingual

Simplest C++ Callback, from SumatraPDF

a year ago
  • #Callbacks
  • #Programming
  • #C++
  • SumatraPDF is a Windows GUI application for viewing PDF, ePub, and comic books, written in C++.
  • Callbacks in GUI programs combine a function and data, known as closures in programming.
  • C++ offers std::function<> and lambdas for closures, but they can complicate crash report analysis due to auto-generated names.
  • The author proposes a simpler, more understandable callback solution than std::function<>, despite its limitations.
  • The solution involves a basic Func0 struct for closures, addressing type safety and casting issues with MkFunc0 template.
  • Func0 and Func1 are introduced for handling callbacks with no arguments and one additional argument, respectively.
  • The author's approach is smaller, faster, and easier to understand than std::function<>, with benefits in size and compilation speed.
  • Despite the boilerplate required, the solution is preferred for its simplicity and the author's familiarity with it.