using KeyMap = std::unordered_map<std::string, int>;The add routine, was changed to use the key as a standard string. The standard string class does not have a member function for converting the string to upper case. For case insensitive dictionaries, the string is converted to upper case using the standard transform function:
std::transform(key.begin(), key.end(), key.begin(), toupper);The first two arguments specify the range of the string to transform (the entire string). The third argument specifies the destination (back into the string). The last argument is function that takes and returns a character. To find a key value in the map, the map find function is used, which returns an iterator. A key not found is detected if the iterator is the end iterator of the map. The value in the map (the index of the entry) is obtained using the iterator:
auto iterator = m_keyMap.find(key);Similar changes were made in the remove function for converting the key to upper case for case insensitive dictionaries. The map erase function is used to remove a key from the map.
if (iterator == m_keyMap.end()) // key not found?
...
index = iterator->index;
[branch stl commit 66561d4532]
No comments:
Post a Comment
All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)