public member function
<queue>
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.
Parameters
- args
- Arguments forwarded to construct the new element.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// priority_queue::emplace
#include <iostream> // std::cout
#include <queue> // std::priority_queue
#include <string> // std::string
int main ()
{
std::priority_queue<std::string> mypq;
mypq.emplace("orange");
mypq.emplace("strawberry");
mypq.emplace("apple");
mypq.emplace("pear");
std::cout << "mypq contains:";
while (!mypq.empty())
{
std::cout << ' ' << mypq.top();
mypq.pop();
}
std::cout << '\n';
return 0;
}
|
Output:
mypq contains: strawberry pear orange apple
|
Complexity
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.
Data races
The container and up to all its contained elements are modified.
Exception safety
Provides the same level of guarantees as the operations performed on the underlying container object.