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

履歴 編集

function
<mdspan>

std::layout_stride::mapping::コンストラクタ(C++23)

constexpr mapping() noexcept;  // (1)

constexpr mapping(const mapping&) noexcept = default;  // (2)

template<class OtherIndexType>
  constexpr mapping(const extents_type&, span<OtherIndexType, rank_>) noexcept;  // (3)

template<class OtherIndexType>
  constexpr mapping(const extents_type&, const array<OtherIndexType, rank_>&) noexcept;  // (4)

template<class StridedLayoutMapping>
  constexpr explicit(see below) mapping(const StridedLayoutMapping&) noexcept;  // (5)

概要

  • (1) : デフォルトコンストラクタ
  • (2) : コピーコンストラクタ
  • (3), (4) : extentsとストライド幅からの構築(定数rank_は次元数)
  • (5) : レイアウトマッピングからの変換コンストラクタ

テンプレートパラメータ制約

  • (3), (4) :
  • (5) :
    • layout-mapping-alike<StridedLayoutMapping>を満たす
    • is_constructible_v<extents_type, typename StridedLayoutMapping::extents_type> == true
    • StridedLayoutMapping::is_always_unique() == true
    • StridedLayoutMapping::is_always_strided() == true

事前条件

  • (1) : layout_right::mapping<extents_type>().required_span_size()を、index_type型で表現できること。
  • (3), (4) :
    • 半開区間[0, rank_)の全てのiに対して、s[i]index_typeへ変換した結果が0より大きいこと。
    • REQUIRED-SPAN-SIZE(e, s)index_type型で表現できること。
    • rank_0より大きいとき、半開区間[1, rank_)の全てのiに対してj = i-1としてs[Pi] >= s[Pj] * e.extents(Pj)を満たすの整数値の組合せPが存在すること。
  • (5) :

効果

例外

投げない

explicitになる条件

説明専用の変数テンプレートis-mapping-ofを下記の通り定義する:

template<class Layout, class Mapping>
constexpr bool is-mapping-of = // exposition only
  is_same_v<typename Layout::template mapping<typename Mapping::extents_type>, Mapping>;

  • (5) : explicit指定子の式は以下と等価

!(is_convertible_v<typename StridedLayoutMapping::extents_type, extents_type> &&
  (is-mapping-of<layout_left, StridedLayoutMapping> ||
   is-mapping-of<layout_right, StridedLayoutMapping> ||
   is-mapping-of<layout_stride, StridedLayoutMapping>))

#include <cassert>
#include <array>
#include <span>
#include <mdspan>

using Ext3x4 = std::extents<size_t, 3, 4>;

int main()
{
  // (1) : デフォルトコンストラクタ
  {
    std::layout_stride::mapping<Ext3x4> map1;
    std::layout_right::mapping<Ext3x4>  map1R;
    assert(map1 == map1R);
  }
  // (2) : コピーコンストラクタ
  {
    std::layout_stride::mapping<Ext3x4> map2_a;
    std::layout_stride::mapping<Ext3x4> map2_b = map2_a;
    assert(map2_a == map2_b);
  }
  // (3) : extentsとストライド幅(span)による構築
  {
    int strides[] = {4, 1};
    std::layout_stride::mapping<Ext3x4> map3{Ext3x4{}, std::span(strides)};
    assert(map3.stride(0) == 4);
    assert(map3.stride(1) == 1);
  }
  // (4) : extentsとストライド幅(array)による構築
  {
    std::array strides{4, 1};
    std::layout_stride::mapping<Ext3x4> map4{Ext3x4{}, strides};
    assert(map4.stride(0) == 4);
    assert(map4.stride(1) == 1);
  }
  // (5) : レイアウトマッピングからの変換コンストラクタ
  {
    std::layout_left::mapping<Ext3x4>   map5L;
    std::layout_stride::mapping<Ext3x4> map5 = map5L;
    assert(map5 == map5L);
  }
}

出力

バージョン

言語

  • C++23

処理系

関連項目

参照