std::swap(std::queue)
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Containers library 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
 Tables
std::queue Defined in header 
 
 
<queue> 
 template< class T, class Container >
 
 (since C++11) void swap( std::queue <T, Container>& lhs,
(until C++17)
template< class T, class Container >
 
 (since C++17) void swap( std::queue <T, Container>& lhs,
           std::queue <T, Container>& rhs )
(constexpr since C++26)
This overload participates in overload resolution only if std::is_swappable_v <Container> is true.
(since C++17)[edit] Parameters
 lhs, rhs
 -
 containers whose contents to swap
[edit] Complexity
Same as swapping the underlying containers.
Exceptions
noexcept specification:  
 (since C++17)noexcept(noexcept(lhs.swap(rhs)))
Notes
Although the overloads of std::swap for container adaptors are introduced in C++11, container adaptors can already be swapped by std::swap in C++98. Such calls to std::swap usually have linear time complexity, but better complexity may be provided.
[edit] Example
Run this code
#include <algorithm> #include <iostream> #include <queue> int main() { std::queue <int> alice; std::queue <int> bob; auto print = [](const auto& title, const auto& cont) { std::cout << title << " size=" << cont.size(); std::cout << " front=" << cont.front(); std::cout << " back=" << cont.back() << '\n'; }; for (int i = 1; i < 4; ++i) alice.push(i); for (int i = 7; i < 11; ++i) bob.push(i); // Print state before swap print("Alice:", alice); print("Bobby:", bob); std::cout << "-- SWAP\n"; std::swap (alice, bob); // Print state after swap print("Alice:", alice); print("Bobby:", bob); }
Output:
Alice: size=3 front=1 back=3 Bobby: size=4 front=7 back=10 -- SWAP Alice: size=4 front=7 back=10 Bobby: size=3 front=1 back=3