The insert function is used to insert an element into the set, and it returns a pair of an iterator to the inserted element (or the element that prevented the insertion) and a boolean value indicating whether the insertion took place. (It is exception for std::set, generally insert() returns iterator).

std::pair<std::set<int>::iterator, bool> result = mySet.insert(6);
if (result.second) {
    std::cout << "Insertion successful. Inserted element: " << *(result.first) << std::endl;
} else {
    std::cout << "Element already exists: " << *(result.first) << std::endl;
}

On the other hand, multiset::insert() function returns an iterator pointing to the inserted element in the multiset container.

Return Values of insert() across Different Containers:

-by Bard

1. Vector:

2. Set (Unique Elements):

3. Multiset (Allowing Duplicates):

4. List (Doubly Linked List):

5. Map (Unique Keys):

6. Multimap (Duplicates Keys Allowed):

Inserting Multiple Elements with insert()