Bug 153294 - Use copy_if, find_if or remove_if to simplify loops
Summary: Use copy_if, find_if or remove_if to simplify loops
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
4.4 all versions
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2023-01-31 15:14 UTC by Hossein
Modified: 2024-03-24 23:03 UTC (History)
3 users (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 2023-01-31 15:14:44 UTC
Since C++11, STL provides means to process containers easier than before via the available functions inside <algorithm>.

In tdf#153109, I have suggested using std::all_of, std::any_of and std::none_of.

Here, I suggest to simplify loops via std::copy_if, find_if or remove_if:

std::copy_if
https://cplusplus.com/reference/algorithm/copy_if/

std::find_if
https://cplusplus.com/reference/algorithm/find_if/

std::remove_if
https://cplusplus.com/reference/algorithm/remove_if/

In the above links, you can find description for each of the above functions. Beyond that, you can find good tutorials for these functions. For example:

Different methods to copy in C++ STL | std::copy(), copy_n(), copy_if(), copy_backward()
https://www.geeksforgeeks.org/different-methods-copy-c-stl-stdcopy-copy_n-copy_if-copy_backward/

For an example of such changes inside LibreOffice code, see this commit:

Simplify Sequence iterations in lingucomponent..lotuswordpro 760a377f7148e623e9e16d24e66f54a401ecb946

You have to make sure that you keep the code behavior unchanged when using the above STD functions.
Comment 1 Radhey Parekh 2023-02-03 16:50:52 UTC
I would like to work on this as I've implemented this in one of my patches. Also, can you please provide me the code pointer to start on? Thanks.
Comment 2 Buovjaga 2023-03-24 14:02:52 UTC
(In reply to Radhey Parekh from comment #1)
> I would like to work on this as I've implemented this in one of my patches.
> Also, can you please provide me the code pointer to start on? Thanks.

You can use git grep to find similar patterns throughout the codebase.
Comment 3 Aron Budea 2024-03-24 23:03:18 UTC
This is a task that multiple people can work on at the same time, no need to assign it to a single person.