#ifndef _BINARY_SEARCH_
#define _BINARY_SEARCH_

template<class RandomAccessIterator, class T>
RandomAccessIterator binary_search (RandomAccessIterator first,
                                    RandomAccessIterator last,
                                    const T& value)
{
    RandomAccessIterator not_found = last, mid;
    while(first != last)
    {
        mid = first + (last - first) / 2;
        if(value == *mid)
                return mid;
        if(value < *mid)
                last = mid;
        else
                first = mid + 1;
    }
    return not_found;
}

#endif
