C++ Standard Library binary_search() Sample

Description

binary_search() performs a binary search on a sorted sequence of elements. It returns a true or false value indicating whether an element was present. A user-supplied comparison function may be optionally specified.

Declaration

	template <class For, class T>
	    bool binary_search(For, For, const T&);
	template <class For, class T, class Cmp>
	    bool binary_search(For, For, const T&, Cmp);

Concept

The example sets up a vector of integers, and then performs a binary search to see if the value 19 is present. The result value true is displayed.

Special Notes:

If you want to find the locations of the matching elements, the functions lower_bound(), upper_bound(), and equal_range() can be used.

Supported
Supported
Supported