user788171
user788171

Reputation: 17553

no matching function for call to 'lower_bound' with newer gcc

I'm having some trouble compiling code that uses std::lower_bound on systems with newer versions of gcc. From my tests, 4.1 works, but 4.6 fails.

Here is the relevant code snippet:

template <typename RandomAccessIterator, typename Value, typename Comparer>
int my_binary_search(RandomAccessIterator const  first, RandomAccessIterator const  last, Value const& value, Comparer comparer)
{
    RandomAccessIterator it(std::lower_bound(first, last, value, comparer));
    //some more code below
}

The error I am seeing is:

error: no matching function for call to ‘lower_bound(const __gnu_cxx::__normal_iterator<int*, std::vector<int> >&, const __gnu_cxx::__normal_iterator<int*, std::vector<int> >&, const int&, bool (*&)(int, int))’
testing.h:37:75: note: candidate is:
/usr/include/c++/4.6/bits/stl_algobase.h:936:5: note: template<class _ForwardIterator, class _Tp> _ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&)

Does anybody have ideas on how to fix this?

Upvotes: 3

Views: 3625

Answers (1)

imer
imer

Reputation: 136

For anyone finding this on google: I had the same issue Includes were "functional" and "list", didnt give me any error lower_bound wasnt defined or anything, just that it couldnt find a matching function.

Including "algorithm" did the trick.. nearly an hour of searching around for such a stupid thing

Upvotes: 3

Related Questions