# Function binary_search_i

## Summary

``````#include <include/EASTL/algorithm.h>

(1) template <typename ForwardIterator, typename T>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value)

(2) template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value, Compare compare)
``````

## Synopsis

``````#include <include/EASTL/algorithm.h>

template <typename ForwardIterator, typename T>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value)
``````

## Description

binary_search_i

Returns: iterator if there is an iterator i in the range [first last) that satisfies the corresponding conditions: !(*i < value) && !(value < *i). Returns last if the value is not found.

Complexity: At most 'log(last - first) + 2' comparisons.

## Source

``````template <typename ForwardIterator, typename T>
inline ForwardIterator
binary_search_i(ForwardIterator first, ForwardIterator last, const T& value)
{
// To do: This can be made slightly faster by not using lower_bound.
ForwardIterator i(eastl::lower_bound<ForwardIterator, T>(first, last, value));
if((i != last) && !(value < *i)) // Note that we always express value comparisons in terms of < or ==.
return i;
return last;
}
``````

## Synopsis

``````#include <include/EASTL/algorithm.h>

template <typename ForwardIterator, typename T, typename Compare>
ForwardIterator binary_search_i(ForwardIterator first, ForwardIterator last, const T &value, Compare compare)
``````

## Description

binary_search_i

Returns: iterator if there is an iterator i in the range [first last) that satisfies the corresponding conditions: !(*i < value) && !(value < *i). Returns last if the value is not found.

Complexity: At most 'log(last - first) + 2' comparisons.

## Source

``````template <typename ForwardIterator, typename T, typename Compare>
inline ForwardIterator
binary_search_i(ForwardIterator first, ForwardIterator last, const T& value, Compare compare)
{
// To do: This can be made slightly faster by not using lower_bound.
ForwardIterator i(eastl::lower_bound<ForwardIterator, T, Compare>(first, last, value, compare));
if((i != last) && !compare(value, *i))
return i;
return last;
}
``````