Skip to content

Latest commit

 

History

History
72 lines (54 loc) · 1.28 KB

File metadata and controls

72 lines (54 loc) · 1.28 KB

swap (非メンバ関数)

  • mdspan[meta header]
  • function[meta id-type]
  • std[meta namespace]
  • mdspan[meta class]
  • cpp23[meta cpp]
friend constexpr void swap(mdspan& x, mdspan& y) noexcept;

概要

2つのmdspanオブジェクトを入れ替える。

効果

説明専用のメンバ変数ptr_, map_, acc_に対して、以下と等価

swap(x.ptr_, y.ptr_);
swap(x.map_, y.map_);
swap(x.acc_, y.acc_);

例外

投げない

#include <cassert>
#include <mdspan>

using Matrix = std::mdspan<double, std::dextents<size_t, 2>>;

int main()
{
  double arr1[] = {1, 2, 3, 4, 5, 6};
  double arr2[] = {4, 3, 2, 1};
  Matrix mat1{arr1, 2, 3};
  Matrix mat2{arr2, 1, 4};

  swap(mat1, mat2);
  assert(mat1.data_handle() == arr2);
  assert(mat1.size() == 4);
  assert(mat2.data_handle() == arr1);
  assert(mat2.size() == 6);
}
  • swap[color ff0000]
  • data_handle()[link data_handle.md]
  • size()[link size.md]

出力

バージョン

言語

  • C++23

処理系

参照