Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Simple use of priority queue

75 views
Skip to first unread message

Paul

unread,
Aug 10, 2015, 2:59:40 AM8/10/15
to
Suppose I have

bool f(int lhs, int rhs)
{
///
}

std::vector<int> vec;

// vec is further set here.

What is the simplest way to set a priority_queue with the elements in vec based on the order defined by f?

Thank you,

Paul

Öö Tiib

unread,
Aug 10, 2015, 5:28:32 AM8/10/15
to
Simplest to me feels to try to type the sentence above in C++:

std::priority_queue<int, std::vector<int>, decltype(&f)> pq( &f, vec );

Was it what you asked?

Paul

unread,
Aug 10, 2015, 7:51:06 AM8/10/15
to
Yes, that's what I asked. Thanks.

Paul

Paul

unread,
Nov 30, 2015, 12:18:48 PM11/30/15
to
On Monday, August 10, 2015 at 10:28:32 AM UTC+1, Öö Tiib wrote:
Is the below also ok? Is this a context in which the type of a function is understood to be the function pointer?

Thank You,

Paul
std::priority_queue<int, std::vector<int>, decltype(f)> pq( f, vec );

Öö Tiib

unread,
Nov 30, 2015, 7:53:02 PM11/30/15
to
No. It can't work ... you need a function pointer not function.
The 'decltype' is keyword not function and looseness in its argument does
not work.

Following variants must work:

std::priority_queue<int, std::vector<int>, decltype(&f)> pq( &f, vec );
std::priority_queue<int, std::vector<int>, decltype(&f)> pq( **f, vec );

That looseness with function (or on current case constructor) function
pointer arguments is perhaps inherited from C ... I have forgot its history.
0 new messages