C++ std swap(multiset)C++ Multiset swap(multiset) is a non-member function of multiset in C++. This is used to swap (or exchange) the contents of two multisets (i.e. x and y) but both the multisets must be of same type although sizes may differ. SyntaxParameterx: First multiset object. y: Second multiset object of the same type. Return valueNone ComplexityConstant. Iterator validityAll iterators, references and pointers referring to elements in both containers remain valid. Note that the end iterators do not refer to elements and may be invalidated. Data RacesBoth containers x and y are modified. No contained elements are accessed by the call. Exception SafetyThis function does not throw an exception. Example 1Let's see the simple example to swap the element of one multiset to another: Output: Multiset contains following elements a b b d In the above example, multiset m1 has five elements and m2 is empty. When you swap m1 to m2 then all the elements of m1 is swapped to m2. Example 2Let's see a simple example to exchange the contents of two multisets: Output: multiset1 contains: 110 220 330 multiset2 contains: 100 100 200 In the above example, contents of two multisets i.e. multiset1 and multiset2 are exchanged to each other. Example 3Let's see a simple example to swap the contents of two multisets: Output: first contains: 17 17 20 second contains: 10 12 75 Example 4Let's see a simple example: Output: Exchange m1 and m2. Contents of m2: 100 100 300 Contents of m1: m1 is now empty. In the above example, contents of multiset m1 are swapped to multiset m2 and after swapping m1 multiset have been cleared. Next TopicC++ multiset |
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