C++ Deque swap()
C++ Deque swap() function exchanges the content of a given deque with the deque passed in the parameter of same type.
second: It is an another deque container whose content is to be swapped with the given deque.
It does not return any value.
Let's see a simple example
After swapping,value of str is: java is a programming language After swapping,value of str1 is: C is a programming language
In this example, swap() function swaps the contents of str and str1. Now, str contains "java is a programming language" and str1 contains "C is a programming language".
Let's see a simple example when the both the deques are of different type.
error: no matching function for call to 'std::deque<char>::swap(std::deque<int>&)
In this example, swap() function throws an error as the type of both the deques are different.
Let's see a simple example when the sizes are different.
Content of first deque:10 20 30 40 50 Content of second deque:1 2 3 4
In this example, swap() function swaps the content of first deque with the second deque.