#include#include int main() { std::vector foo {1, 2, 3}; std::vector bar {4, 5, 6}; foo.swap(bar); for (auto i : foo) { std::cout << i << " "; } std::cout << std::endl; for (auto i : bar) { std::cout << i << " "; } std::cout << std::endl; return 0; }
4 5 6 1 2 3
#include#include #include int main() { std::vector foo {1, 2, 3}; std::vector bar {4, 5, 6}; std::swap_ranges(foo.begin(), foo.end(), bar.begin()); for (auto i : foo) { std::cout << i << " "; } std::cout << std::endl; for (auto i : bar) { std::cout << i << " "; } std::cout << std::endl; return 0; }
4 5 6 1 2 3This code example uses both the C++ Standard Library and the algorithm library.