deque - STL C++

deque<X, A>::swap()

Declaration

void deque<X,A>::swap(deque<X,A>& qrDeque) const;

Description

This is the swap() function for the deque class template.

Header Include

#include <deque>

Example

#include <iostream>
#include <deque>

int main()
{
	using namespace std;

	// Create two deque instances
	deque<char> qD1;
	qD1.push_back('X');
	qD1.push_back('o');
	qD1.push_back('a');
	qD1.push_back('X');
	qD1.push_back('.');
	qD1.push_back('n');
	qD1.push_back('e');
	qD1.push_back('t');

	deque<char> qD2;
	qD2.push_back('S');
	qD2.push_back('T');
	qD2.push_back('L');

	// Output the deques and the swapped versions
	for (int i = 0; i < 2; ++i) {
		cout << "D1  = ";
		deque<char>::iterator qIter;
		for (qIter = qD1.begin(); qIter != qD1.end(); ++qIter) {
			cout << *qIter;
		}
		cout << endl;
		cout << "D2  = ";
		for (qIter = qD2.begin(); qIter != qD2.end(); ++qIter) {
			cout << *qIter;
		}
		cout << endl;
		if (i == 0) {
			cout << "swap deques" << endl;
		}
		qD1.swap(qD2);
	}

	// Keep the window open
	cin.get();
	return 0;
}

Output

deque<X, A>::swap() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.