Namespaces
Variants
Views
Actions

Difference between revisions of "Template:cpp/container/swap"

From cppreference.com
(⊕) Example ⊏ Compare objects are swapped too; see set/multiset::swap()
m (~)
Line 138: Line 138:
 
     // refers to the same element in the other container after the swap. Same is true
 
     // refers to the same element in the other container after the swap. Same is true
 
     // for references.
 
     // for references.
 +
 +
{{#switch:{{{1|}}}
 +
|set|multiset=
  
 
     struct Cmp : std::less<int> {
 
     struct Cmp : std::less<int> {
Line 144: Line 147:
 
     };
 
     };
  
{{#switch:{{{1|}}}
 
|set|multiset=
 
 
     std::{{{1}}}<int, Cmp> s1{ {2, 2, 1, 1}, Cmp{6} }, s2{ {4, 4, 3, 3}, Cmp{9} };
 
     std::{{{1}}}<int, Cmp> s1{ {2, 2, 1, 1}, Cmp{6} }, s2{ {4, 4, 3, 3}, Cmp{9} };
  
Line 155: Line 156:
 
}}
 
}}
 
}
 
}
 
 
|p={{cpp/container/if unord|{{{1|}}}|true|}}
 
|p={{cpp/container/if unord|{{{1|}}}|true|}}
 
|output=
 
|output=

Revision as of 14:57, 31 July 2020

void swap( {{{1}}}& other );
(since {std})
(until C++17)
void swap( {{{1}}}& other ) noexcept(/* see below */);
(since C++17)

Exchanges the contents of the container with those of other. Does not invoke any move, copy, or swap operations on individual elements.


If std::allocator_traits<allocator_type>::propagate_on_container_swap::value is true, then the allocators are exchanged using an unqualified call to non-member swap. Otherwise, they are not swapped (and if get_allocator() != other.get_allocator(), the behavior is undefined).

(since C++11)

Contents

Parameters

other - container to exchange the contents with

Return value

(none)

Exceptions

(none)

(until C++17)
(since C++17)

Complexity

Constant.

Example

See also

specializes the std::swap algorithm
(function template) [edit]