Why cant we use binary_search() function provided by ? solution.cpp: In member f


#1

Why cant we use binary_search() function provided by ?

solution.cpp: In member function ‘int Solution::searchMatrix(std::vector<std::vector >&, int)’:
solution.cpp:13:56: error: no matching function for call to 'binary_search(std::vector::iterator, , int&)'
if(std::binary_search(A[high].begin(),A[high].end,B))
^
solution.cpp:13:56: note: candidates are:
In file included from /usr/include/c++/4.8/algorithm:62:0,
from solution.h:20,
from solution.cpp:-3:
/usr/include/c++/4.8/bits/stl_algo.h:2697:5: note: template<class _FIter, class _Tp> bool std::binary_search(_FIter, _FIter, const _Tp&)
binary_search(_ForwardIterator __first, _ForwardIterator __last,
^
/usr/include/c++/4.8/bits/stl_algo.h:2697:5: note: template argument deduction/substitution failed:
solution.cpp:13:56: note: could not resolve address from overloaded function '(& A)->std::vector<_Tp, _Alloc>::operator[]<std::vector, std::allocator<std::vector > >(((std::vector<std::vector >::size_type)high)).std::vector::end’
if(std::binary_search(A[high].begin(),A[high].end,B))
^
In file included from /usr/include/c++/4.8/algorithm:62:0,
from solution.h:20,
from solution.cpp:-3:
/usr/include/c++/4.8/bits/stl_algo.h:2730:5: note: template<class _FIter, class _Tp, class _Compare> bool std::binary_search(_FIter, _FIter, const _Tp&, _Compare)
binary_search(_ForwardIterator __first, _ForwardIterator __last,


#2

Should be possible. I mean we don’t disable it explicitly.


#3

Try #include algorithm (in braces) at the top!