VOOZH about

URL: https://www.geeksforgeeks.org/cpp/unordered_set-emplace-function-in-c-stl/

⇱ unordered_set emplace() function in C++ STL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

unordered_set emplace() function in C++ STL

Last Updated : 5 Jun, 2023

The unordered_set::emplace() function is a built-in function in C++ STL which is used to insert an element in an unordered_set container. The element is inserted only if it is not already present in the container. This insertion also effectively increases the container size 1.
Syntax

unordered_set_name.emplace(element)

Parameter: This function accepts a single parameter element which is to be inserted in the unordered_set container.
Return Value: This function returns a pair on successful insertion. The pair consists of an iterator pointing to the newly inserted element and a boolean value True. If the element to be inserted is already present in the container then it returns a pair with an iterator pointing to the already present element and a boolean value false.
Below programs illustrate the unordered_set::emplace() function:
Program 1
 


Output: 
sampleSet contains: 25 5 10 15 20

 

Program 2


Output: 
sampleSet contains: Welcome To GeeksforGeeks For Geeks Computer Science Portal

 

Time complexity: O(n) 

Comment