Bug 158337 - Use C++20 std::erase instead of std::remove followed by erase
Summary: Use C++20 std::erase instead of std::remove followed by erase
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:24.8.0
Keywords: difficultyBeginner, easyHack, skillCpp
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2023-11-23 15:07 UTC by Hossein
Modified: 2024-09-18 05:04 UTC (History)
2 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-11-23 15:07:54 UTC
Description:
Now that C++20 is the baseline for LibreOffice code, it is possible to use C++ features that are only available since C++20.

In C++20, it is possible to use std::erase to erase all elements inside a container that are equal to a certain "value". Also, it is possible to use std:erase_if to erase all elements inside a container that satisfy the predicate "pred".

For more information, see this description:

std::erase, std::erase_if (std::vector)
https://en.cppreference.com/w/cpp/container/vector/erase2

See this commit as an example: be1093cce53a3c34a67233391922674c7c62f4e3

Finding instances:

Using grep it is possible to find some instances. For example:
$ git grep std::remove|grep erase

This will not give all the instances, as sometime erase can be a few lines before or after std::remove.
Comment 1 Roman Kuznetsov 2023-11-23 20:42:59 UTC
Set to NEW as EasyHack
Comment 2 Commit Notification 2023-12-31 16:19:39 UTC
Luv Sharma committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158337 use std::erase instead of std::removed followed by erase

It will be available in 24.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 2024-02-12 12:28:47 UTC
varshneydevansh committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2220b3718fd831e78485cba2a272e9af08907ddd

tdf#158337 use std::erase instead of std::remove followed by erase

It will be available in 24.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 2024-05-15 16:17:34 UTC
AmandaQuaresmaCoutinho committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/450edc617aa28b003f02204a1748986a21da3ddf

tdf#158337 Use C++20 std::erase instead of std::remove followed by erase

It will be available in 24.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 Buovjaga 2024-09-18 05:04:29 UTC
(In reply to Hossein from comment #0)
> Using grep it is possible to find some instances. For example:
> $ git grep std::remove|grep erase
> 
> This will not give all the instances, as sometime erase can be a few lines
> before or after std::remove.

Some potential remaining ones can be found with:

git grep -5 std::remove | grep --color=always erase