A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/queue/queue/emplace/ below:

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
queue::push
Insert element (public member function)
queue::pop
Remove next element (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4