Deque or Double-ended queues are sequence containers with the feature of expansion and contraction on both the ends. They are similar to vectors, but are more efficient in case of insertion and deletion of elements at the end, and also the beginning. Unlike vectors, contiguous storage allocation may not be guaranteed.
emplace() function inserts a new element just before the specified position and the size of the container is increased by one.
iterator emplace(const_iterator position, value_type val);
Parameters: This method accepts following paramters:
- position: It defines the position before which the new element is to be inserted.
- val: New value which is to be inserted.
Return value : It returns an iterator to the newly constructed element.
Below examples illustrate this method:
1 2 3 4 5
- deque::pop_front() and deque::pop_back() in C++ STL
- deque::front() and deque::back() in C++ STL
- deque::empty() and deque::size() in C++ STL
- deque::clear() and deque::erase() in C++ STL
- deque::emplace_front() and deque::emplace_back() in C++ STL
- deque::begin() and deque::end in C++ STL
- deque::at() and deque::swap() in C++ STL
- map emplace() in C++ STL
- set::emplace() in C++ STL
- priority_queue emplace() in C++ STL
- multiset::emplace() in C++ STL
- multimap::emplace() in C++ STL
- stack emplace() in C++ STL
- emplace vs insert in C++ STL
- queue::emplace() in C++ STL
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.