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.
Thanks Hossein. Sounds good to me. Marking 4.4 as earliest affected as that's when C++11 started being used AFAIK. (e.g. https://meeksfamily.uk/~michael/blog/2015-01-29-under-the-hood-4-4.html and https://archive.fosdem.org/2015/schedule/event/editors_cpp11_libreoffice/attachments/slides/633/export/events/attachments/editors_cpp11_libreoffice/slides/633/FOSDEM2015_LibreOffice_C_11.pdf)
Hi, I'd like to take a look at this.
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.
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.
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.