public member function
<queue>

std::queue::emplace

template <class... Args> void emplace (Args&&... args);
Construct and insert element
Adds a new element at the end of the queue, after its current last element. 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.

Parameters

args
Arguments forwarded to construct the new element.

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// queue::emplace
#include <iostream>       // std::cin, std::cout
#include <queue>          // std::queue
#include <string>         // std::string, std::getline(string)

int main ()
{
  std::queue<std::string> myqueue;

  myqueue.emplace ("First sentence");
  myqueue.emplace ("Second sentence");

  std::cout << "myqueue contains:\n";
  while (!myqueue.empty())
  {
    std::cout << myqueue.front() << '\n';
    myqueue.pop();
  }

  return 0;
}

Output:

myqueue contains:
First sentence
Second sentence


Complexity

One call to emplace_back on 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 operation performed on the underlying container object.

See also