https://bugs.documentfoundation.org/show_bug.cgi?id=158237
Bug ID: 158237
Summary: Use c++20 contains() instead of find() and end()
Product: LibreOffice
Version: 24.2.0.0 alpha0+ Master
Hardware: All
OS: All
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: Writer
Assignee: [email protected]
Reporter: [email protected]
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.
--
You are receiving this mail because:
You are the assignee for the bug.