deque - STL C++

swap()

Declaration

bool swap(deque<X, A>& qrD1, deque<X, A>& qrD2);

Description

This is the friend function swap() for deques, and it swaps the sets of entries in the two deques qrD1 and qrD2.

Header Include

#include <deque>

Example

#include <iostream>
#include <deque>

int main()
{
	using namespace std;

	// Create a two deque instances and add bits to them
	deque<bool> qD1;
	qD1.push_back(true);
	qD1.push_back(false);
	qD1.push_back(false);
	qD1.push_back(true);

	deque<bool> qD2;
	qD2.push_back(false);
	qD2.push_back(true);

	// Output the deques and the swapped versions
	for (int i = 0; i < 2; ++i) {
		cout << "D1  = ";
		deque<bool>::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;
		}
		swap(qD1, qD2);
	}

	cin.get();
	return 0;
}

Output

swap() Output
 

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