コンテンツにスキップ

C++/標準ライブラリ/mdspan

出典: フリー教科書『ウィキブックス(Wikibooks)』

24.7.3 Multidimensional access (views.multidim)[編集]

このセクションは、多次元アクセスに関する概念を定義しています。

24.7.3.1 Overview (mdspan.overview)[編集]

多次元インデックス空間
カルテジアン積(デカルト積)として表される整数区間です。各区間は、半開範囲 [Li, Ui) として表され、Li は下限、Ui は上限です。
多次元インデックス空間のランクは、その空間が持つ区間の数を表します。
サイズは、各次元 i の (Ui − Li) の積として計算されます。ランクが 0 の場合、サイズは 1 となります。
ランクインデックス
整数 r は、インデックス空間 S のランクインデックスです。範囲は [0, S のランク) です。
多次元インデックス
整数の集まり idx は、インデックス空間 S の多次元インデックスです。
次の条件を満たす必要があります:
  • idx の要素数が S のランクと等しいこと。
  • S の各ランクインデックス i に対して、idx の i 番目の値が S の [Li, Ui) の範囲内であること。

24.7.3.2 Header <mdspan> synopsis (mdspan.syn)[編集]

このセクションでは、<mdspan> ヘッダーの概要が記述されています。

名前空間 std[編集]

クラステンプレート extents
template<class IndexType, size_t... Extents> class extents;
エイリアステンプレート dextents
template<class IndexType, size_t Rank> using dextents = see below ;
レイアウトマッピング
struct layout_left;
struct layout_right;
struct layout_stride;
クラステンプレート default_accessor
template<class ElementType> class default_accessor;
クラステンプレート mdspan
template<class ElementType, class Extents, class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<ElementType>> class mdspan;

24.7.3.3 Class template extents (mdspan.extents)[編集]

24.7.3.3.1 Overview (mdspan.extents.overview)[編集]

このセクションでは、クラステンプレート extents の概要が説明されています。

役割
extents クラスは、ランクが sizeof...(Extents) に等しい多次元インデックス空間を表します。
サブクローズ (24.7) では、extents は多次元インデックス空間の同義語として使用されます。
名前空間 std 内での定義
template<class IndexType, size_t... Extents>
class extents {
public:
    using index_type = IndexType;
    using size_type = make_unsigned_t<index_type>;
    using rank_type = size_t;

    // 観察関数
    static constexpr rank_type rank() noexcept { return sizeof...(Extents); }
    static constexpr rank_type rank_dynamic() noexcept { return dynamic-index (rank()); }
    static constexpr size_t static_extent(rank_type) noexcept;
    constexpr index_type extent(rank_type) const noexcept;

    // コンストラクタ
    constexpr extents() noexcept = default;
    template<class OtherIndexType, size_t... OtherExtents>
    constexpr explicit(see below ) extents(const extents<OtherIndexType, OtherExtents...>&) noexcept;
    template<class... OtherIndexTypes>
    constexpr explicit extents(OtherIndexTypes...) noexcept;
    template<class OtherIndexType, size_t N>
    constexpr explicit(N != rank_dynamic()) extents(span<OtherIndexType, N>) noexcept;
    template<class OtherIndexType, size_t N>
    constexpr explicit(N != rank_dynamic()) extents(const array<OtherIndexType, N>&) noexcept;

    // 比較演算子
    template<class OtherIndexType, size_t... OtherExtents>
    friend constexpr bool operator==(const extents&, const extents<OtherIndexType, OtherExtents...>&) noexcept;

private:
    static constexpr rank_type dynamic-index (rank_type) noexcept;
    static constexpr rank_type dynamic-index-inv (rank_type) noexcept;
    array<index_type, rank_dynamic()> dynamic-extents {};
};
template<class... Integrals>
explicit extents(Integrals...) -> see below ;
要件
IndexType は符号付きまたは符号なしの整数型でなければなりません。
Extents の要素は dynamic_extent と等しいか、IndexType で表現可能でなければなりません。
その他の詳細
extents の各特殊化は正則モデルであり、トリビアルにコピー可能です。
Er は static_extent または dynamic_extent です。