Bug 165233 - Use lambdas instead of std::bind
Summary: Use lambdas instead of std::bind
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:25.8.0
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2025-02-13 14:22 UTC by Hossein
Modified: 2025-04-12 09:35 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2025-02-13 14:22:05 UTC
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/
Comment 1 Commit Notification 2025-03-17 17:10:54 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/39c6e59938f634c2fe40d81620c43a00a1f0e380

tdf#165233 replace std::bind and helper function with lambda

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 2 Commit Notification 2025-03-20 12:29:01 UTC
ArsalanKhan04 committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/5db7fb3c7560f883bc0e2882e34904d9b8d7bd0f

tdf#165233 Use lambdas instead of std::bind

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2025-03-21 05:31:08 UTC
Devashish Gupta committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/52225dfaeb78d2c99dfa7b2ef140183accf668a2

tdf#165233 Use lambdas instead of std::bind

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2025-03-21 09:39:48 UTC
Karthik committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/5a3dd3f0b1e83eca0984b2458fc0f6ee2eb49e4e

tdf#165233 Use lambdas instead of std::bind

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2025-03-21 09:42:50 UTC
Zainab Abbasi committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/dcbf347c6d8c57361dbecdd5891630e5afd42860

tdf#165233 Use lambdas instead of std::bind

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Buovjaga 2025-04-12 09:04:33 UTC
Don't assign multi-hacker tasks to yourself, simply work on them.