public member function
<vector>
std::vector<bool>::swap swap containers (1)void swap (vector& x);swap elements (2)
static void swap (reference ref1, reference ref2);swap containers (1)
void swap (vector& x);swap elements (2)
static void swap (reference ref1, reference ref2) noexcept;
Swap containers or elements
The first signature is the same as described in vector::swap (see vector::swap for more info).A static signature to swap individual elements (bits) is added on vector<bool>.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// vector<bool>::swap
#include <iostream>
#include <vector>
int main ()
{
std::vector<bool> foo;
std::vector<bool> bar;
foo.push_back(false);
foo.push_back(true);
foo.push_back(false);
bar.push_back(true);
bar.push_back(false);
foo.swap (foo[0], foo[1]);
bar.swap (bar.front(), bar.back());
foo.swap(bar);
std::cout << std::boolalpha;
std::cout << "foo contains:";
for (unsigned i=0; i<foo.size(); i++) std::cout << ' ' << foo[i];
std::cout << "\nbar contains:";
for (unsigned i=0; i<bar.size(); i++) std::cout << ' ' << bar[i];
std::cout << '\n';
return 0;
}
foo contains: false true bar contains: true false false
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4