Difference between revisions of "cpp/container/vector bool/swap"
From cppreference.com
< cpp | container | vector bool
(+) |
(P1004R2) |
||
Line 1: | Line 1: | ||
{{cpp/container/vector_bool/title | swap}} | {{cpp/container/vector_bool/title | swap}} | ||
{{cpp/container/vector_bool/navbar}} | {{cpp/container/vector_bool/navbar}} | ||
− | {{ | + | {{dcl begin}} |
+ | {{dcl header | vector}} | ||
+ | {{dcl rev multi | | ||
+ | | dcl1= | ||
static void swap(reference x, reference y); | static void swap(reference x, reference y); | ||
+ | | since2=c++20 | dcl2= | ||
+ | constexpr static void swap(reference x, reference y); | ||
}} | }} | ||
+ | {{dcl end}} | ||
Swaps the contents of {{tt|x}} and {{tt|y}}. | Swaps the contents of {{tt|x}} and {{tt|y}}. |
Revision as of 09:30, 9 August 2020
Defined in header <vector>
|
||
static void swap(reference x, reference y); |
(until C++20) | |
constexpr static void swap(reference x, reference y); |
(since C++20) | |
Swaps the contents of x
and y
.
Contents |
Parameters
x | - | std::vector<bool>::reference value to swap with y
|
y | - | std::vector<bool>::reference value to swap with x
|
Return value
(none)
Complexity
Constant.
Example
Run this code
#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
See also
proxy class representing a reference to a single bool (class) | |
swaps the contents (public member function of std::vector<T,Allocator> )
| |
specializes the std::swap algorithm (function template) |