Namespaces
Variants
Views
Actions

std::vector<bool>::swap

From cppreference.com
Defined in header <vector>
static void swap(reference x, reference y);

Swaps the contents of x and y.

Contents

[edit] Parameters

x - std::vector<bool>::reference value to swap with y
y - std::vector<bool>::reference value to swap with x

[edit] Return value

(none)

[edit] Complexity

Constant.

[edit] Example

#include <vector>
#include <iostream>
 
int main()
{
    std::vector<bool> vb1{ 1,0 };
 
    for (auto e : vb1) { std::cout << e << " "; }
    std::cout << '\n';
 
    vb1.swap(vb1[0], vb1[1]);
 
    for (auto e : vb1) { std::cout << e << " "; }
}

Output:

1 0 
0 1

[edit] See also

proxy class representing a reference to a single bool
(class)
swaps the contents
(public member function of std::vector) [edit]
specializes the std::swap algorithm
(function template) [edit]