Simple binary search in a vector I was reading binary search from an interview book and changed some part of the algorithms.

It is working for all the values I tested with: i.e. all the values in array and outside the array extremes. I would appreciate another person's glance on my use of lower &lt;= upper condition. Any other opinion is welcome, too.

std::pair&lt;bool,size_t&gt; BinarySearch(const std::vector&lt;int&gt;&amp; array, int key) {

auto lower = array.begin();
auto upper = array.end()-1;
while (lower &lt;= upper) {
    auto mid = lower + (upper-lower) /2;
    if(key == *mid)
    {
        return {true,std::distance(array.begin(),mid)};
    }
    if(key &lt; *mid)
        upper = mid-1;
    else
        lower = mid+1;
}

return {false,std::distance(array.begin(),lower)};
}


Usage is as follows:

int main(int argc, const char * argv[]) {

std::vector&lt;int&gt; arr {2,5,11,15};
auto result = BinarySearch(arr,5);
if(result.first)
    std::cout &lt;&lt; result.second &lt;&lt; std::endl;
else
    std::cout &lt;&lt; "Not found " &lt;&lt; std::endl;
return 0;

}
Your code fails if you pass an empty vector because in this case array.end()-1 is incorrect
Keep const correctness, key should be const too
You have kind of strange code formatting, you should rather create an indent after every opening bracket, and not keep function body on a same level
Consider imitating STL approach and returning iterator instead of std::pair
You limit yourself to std::vector&lt;int&gt; type. Read about templates and try to make code that accept different types as well, for example std::vector&lt;double&gt;.
Calling std::vector an array is confusing, note that there's also std::array in C++11 and C-style arrays. vec would be better name there. 
Size of std::vector&lt;int&gt; is not actually std::size_t but std::vector&lt;int&gt;::size_type