public member function
template <class... Args> void emplace (Args&&... args);
Construct and insert element
Adds a new element to the priority_queue. This new element is constructed in place passing args as the arguments for its constructor.
This member function effectively calls the member function emplace_back of the underlying container, forwarding args, and then reorders it to its location in the heap by calling the push_heap algorithm on the range that includes all the elements of the container.
- Arguments forwarded to construct the new element.
#include <iostream> // std::cout
#include <queue> // std::priority_queue
#include <string> // std::string
int main ()
std::cout << "mypq contains:";
std::cout << ' ' << mypq.top();
std::cout << '\n';
mypq contains: strawberry pear orange apple
One call to emplace_back on the underlying container and one call to push_heap on the range that includes all the elements of the underlying container.
The container and up to all its contained elements are modified.
Provides the same level of guarantees as the operations performed on the underlying container object.