The vector::emplace() is an STL in C++ which extends container by inserting new element at position. Reallocation happens only if there is a need of more space. Here the container size increases by one.
template iterator vector_name.emplace (const_iterator position, element);
The function accepts two mandatory parameters which are specified as below:
- position – It specifies the iterator pointing to the position in the container where the new element is to be inserted.
- args – It specifies the element to be inserted to be inserted in the vector container.
Return value: The function returns an iterator which points to the newly inserted element.
Below programs illustrates the above function:
The vector elements are: 15 10 20 30
The vector elements are: 10 20 30 16
The vector elements are: 10 20 16 30
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- unordered_multimap emplace() function in C++ STL
- list emplace() function in C++ STL
- unordered_set emplace() function in C++ STL
- unordered_multiset emplace() function in C++ STL
- set::emplace() in C++ STL
- map emplace() in C++ STL
- vector insert() function in C++ STL
- vector data() function in C++ STL
- vector max_size() function in C++ STL
- Passing vector to a function in C++
- vector shrink_to_fit() function in C++ STL
- vector capacity() function in C++ STL
- deque emplace in C++ STL
- multiset::emplace() in C++ STL
- priority_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.