I have a Queue
class that is basically a single linked list. It has 2 remove methods. What would be the cleanest way to avoid duplication of the code? Only the comparisons in methods are different.
int Queue::remove(const string& substring)
{
// Loop through the queue list
size_t found;
found = current_job->description.find(substring)
if (found != string::npos) {
// Remove job.
}
// Return the amount of removed jobs.
}
int Queue::remove(int priority)
{
// Loop through the queue list
if (current_job->priority == priority) {
// Remove job.
}
// Return the amount of removed jobs.
}
I thought a template solution as answered here, but in this case, the comparison function has different arguments.