最終更新日時(UTC):
が更新

履歴 編集

function
<memory>

std::indirect::swap(C++26)

constexpr void swap(indirect& other) noexcept(see below);

概要

*thisotherの状態を交換する。所有オブジェクトまたは無効値状態を交換する。

事前条件

allocator_traits<Allocator>::propagate_on_container_swap::valuetrueの場合、AllocatorはCpp17Swappable要件を満たすこと。そうでない場合、get_allocator() == other.get_allocator()trueであること。

効果

*thisotherの状態(所有オブジェクトまたは無効値状態)を交換する。propagate_on_container_swap::valuetrueの場合はアロケータも交換する。所有オブジェクトに対して直接swapを呼ぶわけではない。

例外

以下と等価なnoexcept指定を持つ:

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

#include <cassert>
#include <memory>

int main()
{
  std::indirect<int> a{1};
  std::indirect<int> b{2};
  a.swap(b);
  assert(*a == 2 && *b == 1);
}

出力

バージョン

言語

  • C++26

処理系

関連項目

参照