https://bugs.documentfoundation.org/show_bug.cgi?id=165233
Bug ID: 165233
Summary: Use lambdas instead of std::bind
Product: LibreOffice
Version: unspecified
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: LibreOffice
Assignee: [email protected]
Reporter: [email protected]
Description:
std::bind is a mechanism in C++ to bind specific arguments to an existing
function or function object. It is helpful to define a new function that gets
fewer/different parameters but does the same thing. The parameters are
forwarded to the actual underlying function alongside some other values.
https://en.cppreference.com/w/cpp/utility/functional/bind
Although std::bind is handy in some cases, it presents various drawbacks,
including:
1. Reduced readability: std::bind reduces readability, as it uses syntax like
std::placeholders::_1 without a meaningful name.
2. Runtime performance overhead: std::bind introduces runtime overhead.
3. Harder debugging: due to the specific syntax, it is harder to debug and find
problems when dealing with function calls.
4. Issues with overloading: using std::bind, one needs to do explicit casting,
which complicates using overloaded functions.
One advice is to use lambdas instead of std::bind. There are many places in
LibreOffice code where std::bind is used, and the task here is to change those
instances to lambda.
$ git grep std::bind | wc -l
81
You can pick an instances of using std::bind, and use lambdas to do the exact
same thing. You have to make sure that the code behavior remains the same after
your change.
Example:
This is an example code, which shows how to define lambda where std::bind was
used before:
Use lambda instead of std::bind + wrapper function
81e9703cf8f891bfb36f52eb24e0e18ca13d373a
More information:
For understand std::bind and lambdas better, and to see some examples, please
refer to the relevant C++ documentation. These are some useful links:
std::bind
https://en.cppreference.com/w/cpp/utility/functional/bind
Lambda expression in C++
https://www.geeksforgeeks.org/lambda-expression-in-c/
Lambda Vs Binders in C++ STL
https://www.geeksforgeeks.org/lambda-vs-binders-in-cpp-stl/
--
You are receiving this mail because:
You are the assignee for the bug.