In code I have queue of Events
sorted by waitTime
. I want to find which Events
should be executed for the current moment, so I do this:
std::vector<Event>::iterator up = std::upper_bound(queue.begin(), queue.end(), currentTime);
The std::upper_bound
will work if I overload <
operator:
bool Event::operator<(const double& currentTime) const
{
return waitTime < currentTime;
}
But I have an error:
error: no match for ‘operator<’ (operand types are ‘const double’ and ‘Event’)
How should I correctly overload ‘operator<’ ?
P.S
class Event{
public:
double startTime;
double waitTime;
double size;
Event(double start, double wait, double size);
bool operator<(const Event& otherEvent) const;
bool operator<(const double& currentTime) const;
bool operator() (const Event & event, const double & right);
};