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 target:25...
Keywords: difficultyBeginner, easyHack, skillCpp, topicCleanup
Depends on:
Blocks: Dev-related
  Show dependency treegraph
 
Reported: 2023-11-16 10:31 UTC by Hossein
Modified: 2025-03-27 16:35 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.
Comment 12 Commit Notification 2024-11-23 13:47:42 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

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

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 13 Commit Notification 2024-11-29 00:37:57 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/678f732d9cc5b9a73e633d77bd2d1ae34700ed3d

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 14 Commit Notification 2024-11-29 19:48:09 UTC
Bogdan Buzea committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/991a7b44da24cce0a828ec8f2d7472ce76cbab79

tdf#158237 sw: 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 15 Commit Notification 2024-11-29 19:49:12 UTC
Bogdan Buzea committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/905fa8f49d98d7ce986333b781f0462be6dfa49e

tdf#158237 chart2: 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 16 Commit Notification 2024-11-29 19:50:15 UTC
Bogdan Buzea committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 dbaccess: 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 17 Commit Notification 2024-11-29 19:50:18 UTC
Bogdan Buzea committed a patch related to this issue.
It has been pushed to "master":

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

tdf#158237 connectivity: 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 18 Commit Notification 2024-11-29 19:51:20 UTC
Manish committed a patch related to this issue.
It has been pushed to "master":

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

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 19 Commit Notification 2024-12-05 07:04:23 UTC
Rosh committed a patch related to this issue.
It has been pushed to "master":

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

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

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 20 Commit Notification 2024-12-27 15:21:24 UTC
Johann committed a patch related to this issue.
It has been pushed to "master":

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

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

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 21 Commit Notification 2025-01-01 18:44:16 UTC
kkasliwal committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7994ecabf6841512fd2449d161686ace9221c60d

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

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 22 Commit Notification 2025-02-23 21:25:49 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/1fc03eaed2899ac041f660f54cb1facb71390ccf

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

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 23 Commit Notification 2025-02-24 12:31:08 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

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

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

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 24 Commit Notification 2025-02-26 00:57:49 UTC
Simon Chenery committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/321881ca09ccb84a8d8c12f2aa0df9f54b2521ae

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

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 25 Commit Notification 2025-03-21 20:31:30 UTC
Devashish Gupta committed a patch related to this issue.
It has been pushed to "master":

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

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

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 26 Commit Notification 2025-03-27 16:35:44 UTC
Nam Bui committed a patch related to this issue.
It has been pushed to "master":

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

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

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.