Bug 170269 - Use C++20 ranges all_of, any_of or none_of to simplify loops for checking a condition over a range
Summary: Use C++20 ranges all_of, any_of or none_of to simplify loops for checking a c...
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:26.8.0
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2026-01-08 14:37 UTC by Hossein
Modified: 2026-01-20 13:45 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 2026-01-08 14:37:58 UTC
Since C++20, it is possible to process containers in an easier form with std::ranges. One can rewrite loops checking a condition over a range with std::ranges functions. It is also simpler compared to C++11 syntax.

There are multiple functions available in ranges library:

Constrained algorithms (since C++20)
https://en.cppreference.com/w/cpp/algorithm/ranges.html

These are defined in <algorithm> header:

std::ranges::all_of
  Test the condition on all of the elements
std::ranges::any_of
  Test if any element satisfies the condition
std::ranges::none_of
  Test if no elements satisfies the condition

You can find further information below. Above functions are part of "Non-modifying sequence operations":
https://en.cppreference.com/w/cpp/algorithm/ranges/all_any_none_of.html

The new std::ranges has a simpler syntax compared to the older std::all_of, etc. functions used in tdf#153109, and is a replacement, in most cases.

For an example commit, see this patch:

Use C++20 std::ranges::all_of instead of a loop
https://gerrit.libreoffice.org/c/core/+/196851

Please make sure that you keep the code behavior unchanged.
Comment 1 Roman Kuznetsov 2026-01-10 20:43:41 UTC
Set to NEW as EasyHack
Comment 2 Commit Notification 2026-01-20 13:45:19 UTC
Hossein committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/00dfdd0154a25c56723296958b1d08f7fa07763a

tdf#170269 Use C++20 std::ranges::all_of instead of a loop

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.