날짜 벡터를 실행하기 위해 사용자 지정 이진 검색을 구현하려고합니다. 내가 컴파일 오류 때 얻을 그러나 문제없이 컴파일비교 기능을 사용하는 C++ <오버로드 된 함수 유형>
template <class T>
inline bool cmp(T lhs,T rhs)
{
return lhs<rhs;
}
이 두 :
template <typename RandomAccessIterator, typename Value, typename Comparer>
inline int binary_search(RandomAccessIterator const first, RandomAccessIterator const last, Value const& value, Comparer comparer)
{
RandomAccessIterator it(std::lower_bound(first, last, value, comparer));
if (it == last || comparer(*it, value) || comparer(value, *it))
return distance(first,last);
return distance(first,it);
}
내가 사용하고 비교기는 다음과 같이 정의된다
내 이진 검색 기능은이 다음이다 다음 코드를 사용하여 binary_search 함수를 호출 해보십시오.
whe re date_list는 날짜를 포함하는 벡터이고, date2는 int입니다.
정확한 오류 메시지는 다음과 같습니다이 문제를 해결하는 방법에 대한
error: no matching function for call to ?binary_search(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, int&, <unresolved overloaded function type>)?
어떤 아이디어?
감사합니다. 이것은 제가 놓친 것이고 완벽하게 작동합니다. – user788171