Javatpoint Logo
Javatpoint Logo

C++ multiset emplace()

C++ Multiset emplace() function is used to extend the multiset container by inserting new elements into the container. Elements are built directly (neither copied nor moved).

The constructor of the element is called by giving the arguments args passed to this function.



args: The arguments forwarded to construct an element to be inserted into the container.

Return value

emplace() function returns a bool pair that will indicate if the insertion is occurred or not, and returns an iterator pointing to the newly inserted element.


Logarithmic in the container size.

Iterator validity

No changes.

Data Races

The container is modified.

Iterating ranges in the container is not safe although concurrently accessing exiting elements is safe.

Exception Safety

If an exception is thrown, there are no changes in the multiset container.

Example 1

Let's see the simple example to insert the elements into the multiset:


Multiset contains following elements
a, a, b, b, c,

In the above example, it simply inserts the element into the multiset m with the given values.

Example 2

Let's see a simple example to insert the element and check for the duplicate key:


multiset modified, now contains 3 elements: (Deep) (Kesharwani) (Nikita) 

multiset modified, now contains 4 elements: (Deep) (Kesharwani) (Nikita) (Nikita)

Example 3

Let's see a simple example to find the sum of the inserted elements:


Sum of elements is: 16

Example 4

Let's see a simple example to insert the element:


Enter the number of family members: 3
Enter the name of each member: 

Total member of family is: 3
Details of family members: 


In the above example, it simply inserts the elements by the user's choice.

Next TopicC++ multiset

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA