claudius
claudius

Reputation: 1144

C++ STL container priority queue initialisation

from http://www.cplusplus.com/reference/queue/priority_queue/priority_queue/

//initialize (1)    
explicit priority_queue (const Compare& comp = Compare(),
                         const Container& ctnr = Container());


//range (2) 
template <class InputIterator>
         priority_queue (InputIterator first, InputIterator last,
                         const Compare& comp = Compare(),
                         const Container& ctnr = Container());

Based on answers to similar question on SO, I am using

priority_queue<int, vector<int>, greater<int> > pq

However, this definition doesn't match with either 1 or 2 given in the reference site. So how is this initialisation working?

Upvotes: 0

Views: 226

Answers (1)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385405

You're only looking at the reference for the constructor.

The template parameter list you need to look at is the template parameter list for the class template itself:

template<
    class T,
    class Container = std::vector<T>,
    class Compare = std::less<typename Container::value_type>
> class priority_queue;

You're instantiating a std::priority_queue with all three template parameters given explicitly, and doing so using the first constructor (which is not a function template — the second constructor is) and taking the defaults of both its arguments.

Upvotes: 3

Related Questions