Namespaces
Variants
Actions

std::polymorphic<T, Allocator>::swap

From cppreference.com
< cpp‎ | memory‎ | polymorphic
 
C++
 
Memory management library
(exposition only*)
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
(until C++20*)
(until C++20*)

Garbage collector support (until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
(C++11)(until C++23)
 
std::polymorphic
constexpr void swap( polymorphic& other ) noexcept(/* see below */);
(since C++26)

Swaps the contents with those of other.

In the description below, swap_allocators refers to std::allocator_traits<Allocator>::propagate_on_container_swap::value.

Swaps the states of *this and other, exchanging owned objects or valueless states.

  • If swap_allocators is true, then executes using std::swap;
    swap(alloc , other.alloc );.
  • Otherwise, the allocators are not swapped.

If one of the following conditions is satisfied, the behavior is undefined:

  • swap_allocators is true, and Allocator does not satisfy the requirements of Swappable.
  • swap_allocators is false, and get_allocator() == other.get_allocator() is false.

Contents

[edit] Parameters

other - the polymorphic object to exchange the contents with

[edit] Exceptions

noexcept specification:  
noexcept(std::allocator_traits<Allocator>::propagate_on_container_swap::value
             || std::allocator_traits<Allocator>::is_always_equal::value)

[edit] Example

[edit] See also

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

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant