Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Hyokun_Y_
Beginner
40 Views

specifying comparator of concurrent_priority_queue in runtime

Is it possible to specify the comparator of tbb::concurrent_priority_queue in runtime, as in std::priority_queue?

In std::priority_queue, you can pass the comparator as an argument of the constructor. For example, see 'sixth' of the following example.  http://www.cplusplus.com/reference/queue/priority_queue/priority_queue/

However, it seems like tbb::concurrent_priority_queue does not receive comparator as an argument, and creates one itself using the default constructor. Is there any way to specify it in runtime?

Thanks,
Hyokun Yun 

0 Kudos
2 Replies
Jackson_M_Intel
Employee
40 Views

It is correct that the comparator cannot be dynamically specified. We can take this as a feature request. In order to more clearly understand the decision, would you be able to share a bit more about what you would like to do with that ability? I.e. why is it importatnt, what's your use case?

Thanks.

RafSchietekat
Black Belt
40 Views

Two threads about the same subject: this must be important...

I've already officially submitted a possible contribution to address this (just a matter of introducing a new set of constructors).

BTW, the C++ templates that use comparators apparently store ((ordered) associative containers, priority_queue) or even accept (sorting and related operations) them only by value (do tell if I overlooked anything), not by reference, but I don't see a need to second-guess that in TBB. Not to say that it was the right choice, but if you're in control of what comparator class to use, there's always embedding as a workaround against object slicing, and otherwise I would be curious about a use case that would run into this general limitation.

Reply