SumatraPDF is a Windows GUI application for viewing PDF, ePub and comic books written in C++.
A common need in GUI programs is a callback. E.g. when a button is clicked we need to call a function with some data identifying which button was clicked. Callback is therefore a combo of function and data and we need to call the function with data as an argument.
In programming language lingo, code + data combo is called a closure.
C++ has std::function<> and lambdas (i.e. closures). Lambdas convert to std::function<> and capture local variables.
Lambdas can be used as callbacks so problems solved?
Not for me.
I’ve used std::function<> and I’ve used lambdas and what pushed me away from them were crash reports.
I’ve implemented crash reporting and it’s been very useful.
The problem with lambdas is that they are implemented as compiler-generated functions. They get non-descriptive, auto-generated names. When I look at call stack of a crash I can’t map the auto-generated closure name to a function in my code. It makes it harder to read crash reports.
Simplest solution that could possibly work
... continue reading