mercredi 11 mars 2015

How to use default comparator in own class?

I want to create own data container like STL-containers.



template <class priorityType = size_t, class Compare = std::less<priorityType>>
class task_queue
{
public:
task_queue(Compare c = Compare())
{

}

private:
std::priority_queue<priorityType, std::vector<priorityType>, Compare> tasks_id;
};

int main() {
struct foo
{
int a;
};

struct foo_compare
{
bool operator()(const foo& lhs, const foo& rhs) const {
return lhs.a < rhs.a;
}
};

task_queue<foo, foo_compare> queue{ foo_compare() };
}


I want to use comparator, which is passed to constructor, in tasks_id PQ. How can I do this?


Aucun commentaire:

Enregistrer un commentaire