C++ set emplace_hint()C++ set emplace_hint() function is used to extend the set container by inserting new elements into the container using hint as a position for element. Elements are built directly (neither copied nor moved). The constructor of the element is called by giving the arguments args passed to this function. Insertion takes place only if key is not present already. SyntaxParameterargs: The arguments forwarded to construct an element to be inserted into the set. position: Hint for the position to insert the new elements. Return valueIt returns an iterator to the newly inserted elements. If element is already exist, insertion is failed and returns iterator to the existing element. ComplexityIf position is not specified then complexity will be logarithmic in container size. If position is given then complexity will be amortized constant. Iterator validityNo changes. Data RacesThe container is modified. Iterating ranges in the container is not safe although concurrently accessing exiting elements are safe. Exception SafetyIf an exception is thrown, there are no changes in the container. Example 1Let's see the simple example to insert the elements into the set: Output: Set contains following elements 10 20 30 40 50 60 In the above example, it simply inserts the element into the set m with the given value in the given positions. Example 2Let's see a simple example: Output: set starting data: 3 elements: Rakesh Ram Sunil set modified, now contains 4 elements: Deep Rakesh Ram Sunil Example 3Let's see a simple example to insert the elements into the set with the given position: Output: myset contains: [a] [b] [c] Example 4Let's see a simple example to insert the elements: Output: Enter the number of fmly members : 4 Enter the name of each member: Deep Sonu Ajeet Bob Total memnber of fmly is:4 Details of fmly members: Name ________________________ Ajeet Bob Deep Sonu In the above example, it simply inserts the elements by the user's choice in the beginning of set. Next TopicSet key_comp() Function |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India