TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ Queue emplace() Function

C++ Queue emplace() Function with Examples on tutorial for beginners and professionals, constructor, emplace(), empty(), pop(), push(), back(), size(), top(), object and class, exception, static, structs, inheritance, aggregation etc.

<< Back to CPP

C++ Queue emplace() Function

C++ Queue emplace() function adds a new element at the end of the queue, following the current back element. The function performs the insertion operation on the queue.

Syntax

template <class... Args> void emplace (Args&&... args);

Parameters

args: The parameter forwards the argument for the construction of a new element. It specifies the value of the newly constructed element, which is to be inserted at the end position.

Return value

The function is used only for the addition of new elements and does not return any value.

Example 1

#include<iostream>
#include<queue>
#include<string>
int main()
{
	std::queue<std::string> newqueue;
	newqueue.emplace("I am the first line");
	newqueue.emplace("I am the second one");
	std::cout << "Contents of new queue: \n";
	while (!newqueue.empty())
	{
		std::cout << newqueue.front() << "\n";
		newqueue.pop ();
	}
	return 0;
}

Output:

I am the first line
I am the second one

Example 2

#include<iostream>
#include<queue>
#include<string>
using namespace std;
int main()
{
	queue<string> newpqueue;
	newpqueue.emplace("portal");
	newpqueue.emplace("computer science");
	newpqueue.emplace("is a");
	newpqueue.emplace("TheDeveloperBlog");
	cout << "newpqueue = " ;
	while(!newpqueue.empty( ) )
	{
		cout<< newpqueue.front() << " ";
		newpqueue.pop();
	}
	return 0 ;
}	

Output:

TheDeveloperBlog is a computer science portal

Complexity

One call is made to the emplace_back.

Data races

All the elements present in the queue are modified, as with the addition of a new element the respective positions of all the other elements are also changed.

Exception Safety

Guarantee as equivalent to the operations that are performed on the underlying container object is provided.

Next TopicC++ Queue




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf