Template argument for comparator when passing priority queue to a function
04:46 01 Feb 2022

I am new to C++ and still learning the concepts. I am trying to pass a priority queue with custom comparators to a templated function. I want to abstract the comparator type in priority queue template argument list when I pass it to the function in the function definition.

Here is an example of what I am trying to do:

File1.h:

struct my_comparator
{
    bool operator()(const some_type* c1, const some_type* c2) {
        c1->property < c2->property;
    }

    another_function(….)
    {
        std::priority_queue, my_comparator> my_queue;

        some_function(my_queue);
    }
}

File2.h:

some_function(std::priority_queue, comparator_type> queue_)
{
    // implementation
}

I want to understand what to pass as the comparator type in the priority queue template of some_function definition, such that it can accept any custom comparator I define (adhering to the required format), in the file that is calling the function (which is File1.h in this case).

PS: this is my first time posting here. Apologies in advance for any format mistakes.Thank you!

c++ templates comparator priority-queue abstraction