Namespaces
Variants

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

From cppreference.net
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* )
( 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)
constexpr void swap ( polymorphic & other ) noexcept ( /* see below */ ) ;
(自 C++26 起)

other 交换内容。

在以下描述中, swap_allocators 指代 std:: allocator_traits < Allocator > :: propagate_on_container_swap :: value

交换 * this other 的状态,互换所拥有的对象或无值状态。

  • swap_allocators true ,则执行 using std:: swap ;
    swap ( alloc  , other. alloc  ) ;
  • 否则,分配器不会被交换。

若满足以下任一条件,则行为未定义:

  • swap_allocators true ,且 Allocator 不满足 Swappable 要求时。
  • swap_allocators false ,且 get_allocator ( ) == other. get_allocator ( ) false 时。

目录

参数

其他 - 要交换内容的 polymorphic 对象

异常

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

示例

参见

特化 std::swap 算法
(函数模板)