I have a application which uses the multimap
from STL in C++.
In multimap
, I have to use find
function with my custom function. ie Suppose, the contents of my multimap are {"Hello", "World"}, "{"Bye", "World"} and {"Foo", "Bar"}
.
I want to search for the key which contains "e" in itself, ie the it should only return "Hello" and "Bye".
How can I do that ?
Basically, instead of the already defined find function which checks for the absolute equality, I want to define my own custom equality ?
A map(and multimap) in c++
is a datastructure optimized for searching by the key. However the search is performed using the comparison operator used when declaring the map. If you need to perform any search using a different comparison(in this case the letters contained in the key), you will not be able to make use of the good performance of the find operation. Your only option will be to perform linear search. Another option is to declare the map with a different(custom) comparison operator.