Bug 153109 - Use all_of, any_of or none_of from STD instead of looping to check a condition over a range
Summary: Use all_of, any_of or none_of from STD instead of looping to check a conditio...
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: target:24.2.0 target:25.2.0 target:25...
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2023-01-19 14:57 UTC by Hossein
Modified: 2026-05-16 13:04 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-19 14:57:24 UTC
Since C++11, STL provides means to process containers easier than before. Some of the available functions inside <algorithm> are describe below:

std::all_of
  Test the condition on all of the elements
  https://cplusplus.com/reference/algorithm/all_of/
std::any_of
  Test if any element satisfies the condition
  https://cplusplus.com/reference/algorithm/any_of/
std::none_of
  Test if no elements satisfies the condition
  https://cplusplus.com/reference/algorithm/none_of/

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:

The big STL Algorithms tutorial: all_of, any_of, none_of
https://www.sandordargo.com/blog/2019/02/20/stl-algorithm-tutorial-part-1-any-all-none

For examples of such changes inside LibreOffice code, see this commits:

writerfilter: use std::any_of() e542b622aeb70230365971cab4838dbe0b6e0a93%5E%21

desktop: simplify code by std::none_of b4848def4684ad277af23a10d73b4b5c9cb201fb

xmloff: simplify code by using std::all_of/std::any_of/std::none_of c675a2d669c191f3b18ae006c78ef83efba14c30

You have to make sure that you keep the code behavior unchanged when using the above STD functions.
Comment 2 Baole Fang 2023-03-12 21:12:33 UTC
Hi, I'd like to take a look at this.
Comment 3 Mike Kaganski 2023-03-15 03:18:51 UTC
Note that a common sense should apply: this change should not be applied when it doesn't improve things: sometimes the loop is optimal both in terms of performance and readability.
Comment 4 Commit Notification 2023-06-12 11:11:18 UTC
Paris Oplopoios committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/81e815edbf5b4694789aa1d7b9e3ecde08b08b21

tdf#153109 Use any_of instead of loop to check a range

It will be available in 24.2.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 2024-09-01 14:08:30 UTC
Sohrab Kazak committed a patch related to this issue.
It has been pushed to "master":

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

tdf#145538 tdf#153109 Use all_of / range-based for loops

It will be available in 25.2.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 Commit Notification 2024-12-28 14:44:22 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

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

tdf#153109 Use any_of instead of loop to check for match

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 7 Commit Notification 2025-01-22 19:48:18 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4bad8cb5fd321b10ad648ea1674a9f790c5aef1a

tdf#153109 Use any_of to check for match in gciterator.cxx

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 8 Commit Notification 2025-01-28 06:05:27 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/67444270826e17b8ae7b38b7519365b34dde5601

tdf#153109 Use any_of to check for match in spelldsp.cxx

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 9 Commit Notification 2025-02-03 10:30:43 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/9df6108dd7bd301a1b8d60c08b2f2d508c8bd125

tdf#153109 simplify any_of to find without 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 10 Commit Notification 2025-06-23 13:14:31 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/2e8d637e2d9f7a95e045cc2d18e34a29fcc2d87c

tdf#153109 replace loop with std::any_of in impedit2.cxx

It will be available in 26.2.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 11 Commit Notification 2026-03-06 04:24:34 UTC
Teodora Stefan committed a patch related to this issue.
It has been pushed to "master":

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

tdf#153109 Use all_of and any_of from STD instead of looping

It will be available in 26.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 12 Commit Notification 2026-04-26 14:44:46 UTC
Rafał Dobrakowski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/3db7176000dfbc024951b56e75d33925873fd5aa

tdf#153109 Use std::any_of to simplify loop in sp2bv.cxx

It will be available in 26.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 13 Commit Notification 2026-05-06 05:36:45 UTC
Mehul Sharma committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/882784dd00434d8d8b87384487ff0a82e9637bdd

tdf#153109 Use std::any_of instead of loops in sc

It will be available in 26.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 14 Commit Notification 2026-05-07 19:16:03 UTC
Asad Tauqeer committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/241e14a7625f53647b865fea61e039684251d411

tdf#153109 replace for loop in unmarshal.cxx

It will be available in 26.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 15 Commit Notification 2026-05-16 13:04:11 UTC
Asim Raza committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/31889dedea153a9c205edcf39c285a74585c643e

tdf#153109 tdf#170269 Use STL algorithms and std::ranges over manual loops

It will be available in 26.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.