Answer the question
In order to leave comments, you need to log in
Why doesn't lower_bound see operator even though it's defined?
I have this piece of code:
bool operator<(const char l, const string& h) {
return l < h[0];
}
template <typename RandomIt>
pair<RandomIt, RandomIt> FindStartsWith(
RandomIt range_begin, RandomIt range_end,
char prefix)
{
auto left = lower_bound(range_begin, range_end, prefix);
auto right = upper_bound(range_begin, range_end, prefix);
return {left, right};
}
no match for ‘operator<’ (operand types are ‘const char’ and ‘const std::__cxx11::basic_string<char>’)
Answer the question
In order to leave comments, you need to log in
operator<
searched through ADL. You can't define an operator for foreign types and have the algorithms pick it up. I propose this solution: instead of char, look for your own structure (it can be defined simply as a struct with char), for which you can define a comparison in the same way as you did with char.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question