The emplace_front function in C++ for deques inserts a new element at the front of the deque container, consequently expanding the container's size by one.
Syntax
void emplace_front(value_type val);
Parameter
A value is to be added at the start of the deque for insertion.
Return value
It does not return any value.
Example 1
Let's see a simple example
#include <iostream>
#include<deque>
using namespace std;
int main()
{
deque<string> fruit={"mango","banana"};
deque<string>::iterator itr;
fruit.emplace_front("apple");
fruit.emplace_front("strawberry");
for(itr=fruit.begin();itr!=fruit.end();++itr)
std::cout << *itr<<" ";
return 0;
}
Output:
strawberry apple mango banana
In this instance, the emplace_front method inserts two strings, specifically "apple" and "strawberry", at the start of the deque.