How does generic find() function works in C++ STL?
find(): The find() function is used to search the element in the given range and every STL container has the functionality to search the element using find() function. The generic find function works on every data type.
- It returns an iterator to the first element in the range [first, last) that equals to the given key.
- If no such element is found, the function returns the iterator to the last element.
- Vector of different data types like int, string, etc and one key element has been taken.
- Based on the key element search function is called.
- The working mechanism of the search function is written using a template.
- The function searches the element from the start to the end of the vector, based on the key element. If the value doesn’t exist, then it will return the end iterator.
- If the key element matches with the vector element, then it will return the element along with its position.
Below is the C++ program to illustrate the implementation of generic find() in vector:
100 is not present GFG is present at position 3