Bug 158237 - Use C++20 contains() instead of find() and end()
Summary: Use C++20 contains() instead of find() and end()
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
24.2.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:24.8.0 target:25.2.0
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2023-11-16 10:31 UTC by Hossein
Modified: 2024-10-25 13:23 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-16 10:31:53 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.

One of the new features of C++20 is the availability of new functions for working with containers more conveniently. This EasyHack is about using contains().

See this commit: 06e3877dc2cf22e00d04b48453e9ab0b948c3ca2

Other than the first part, which is the introduction of contains(), you see changes like this for some variables of type map:

-    CPPUNIT_ASSERT(aMap.find("LocalURL") != aMap.end());
+    CPPUNIT_ASSERT(aMap.contains("LocalURL"));

Instead of searching for a specific key, and when reaching .end() concluding that the value is not there, the new code is simply using contains() function to check if the key is present in the map, or not.

The actual map data type is SequenceAsHashMapBase, and is based on std::unordered_map.

You can read more about contains() here:
https://en.cppreference.com/w/cpp/container/map/contains

Finding instances:
You an use grep to find some instances. For example:

$ git grep -n -i "map.find(" | grep "!=" | grep "end("

Working with IDEs:
If your IDE is a few years old, there is a chance that it can not recognize contains(). Also, if you have built the project file before, you may have to rebuild the project again. This is needed to make sure that the project files contain the C++20 compatibility option, and not for example C++17.
https://wiki.documentfoundation.org/Development/IDE
In any case, you need to make sure that LibreOffice can be built correctly.
Comment 1 Commit Notification 2024-01-01 11:06:24 UTC
Luv Sharma committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 chart2: use c++20 contains() instead of find() and end()

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 2 Commit Notification 2024-02-13 13:05:00 UTC
Steven Casey (SMCode) committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 comphelper: Use C++20 contains() instead of find() and end()

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-13 18:54:48 UTC
AkshayWarrier committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/488cd78f3b30f8b43007a3250d0c11fd0416dde9

tdf#158237 comphelper: Use C++20 contains() instead of find() and end()

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-03-09 11:28:31 UTC
Sujatro Bhadra committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 Use C++20 contains() instead of find() and end()

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 Commit Notification 2024-03-23 19:16:43 UTC
Beeram_12 committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7174403b03a7effe8bedf78368c09840b4fdf7a9

tdf#158237 use c++20 contains() instead of find() and end()

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 6 Commit Notification 2024-03-26 07:20:16 UTC
RMZeroFour committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/74299624ec810f9683326608ad398211cf51787b

tdf#158237 Use contains instead of find-end

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 7 Commit Notification 2024-03-29 13:59:14 UTC
Aaron Bourdeaux committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6c358c28c5cc2d1d8d8bb9d1238e3546a9bf3ce8

tdf#158237 Use C++20 contains() instead of find() and end()

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 8 Commit Notification 2024-06-21 14:42:56 UTC
Zainab Abbasi committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 Use C++20 contains() instead of find() and end()

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 9 Commit Notification 2024-08-27 17:14:39 UTC
Sohrab Kazak committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/84662e0454eddd928dfdf3cd8f7fe675db6a1fcf

tdf#158237 Using C++20 contains instead of find() and end()

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 10 Commit Notification 2024-10-18 08:03:27 UTC
Sakura286 committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7bd9aaccb99287e4e50fb18759edc7688502a1fb

tdf#158237 comphelper: Use C++20 contains() instead of find() and end()

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 11 Commit Notification 2024-10-25 13:23:54 UTC
Jack Honour committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 Use C++20 contains() instead of find() and end()

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.