https://bugs.documentfoundation.org/show_bug.cgi?id=170270

            Bug ID: 170270
           Summary: Use C++20 ranges copy_if, find_if or remove_if to
                    simplify loops
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: [email protected]
          Reporter: [email protected]

Since C++20, it is possible to process containers in an easier form with
std::ranges. One can rewrite loops with std::ranges functions. It is also
simpler compared to C++11 syntax.

In tdf#170269, I have suggested using std::ranges::all_of, std::ranges::any_of
and std::ranges::none_of. If you want to check/validate a condition over a
range, refer to that issue. 

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:

Copy certain elements of a range
std::ranges::copy_if
https://en.cppreference.com/w/cpp/algorithm/ranges/copy.html

Remove elements from a range
std::ranges::remove_if
https://en.cppreference.com/w/cpp/algorithm/ranges/remove.html

Find element in a range
std::ranges::find_if
https://en.cppreference.com/w/cpp/algorithm/ranges/find.html

You can find further information in the above links. These functions (except
find_if) are part of "Modifying sequence operations".

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

Please make sure that you keep the code behavior unchanged.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to