名稱空間
變體
操作

C++ 命名需求: LayoutMapping (自 C++23 起)

來自 cppreference.com
 
 
C++ 命名要求
基本
型別屬性
全庫範圍




Container(容器)
容器元素
迭代器 (Iterator)
流 I/O
格式化器
(C++20)
隨機數
併發
(C++11)
Ranges
多維檢視
LayoutMapping(佈局對映)
(C++23)
其他

 

LayoutMapping 控制多維索引到 std::mdspan 中資料控制代碼的一維偏移量的對映。

目錄

[編輯] 要求

型別 M 滿足 LayoutMapping,如果它建模 copyableequality_comparable,並且以下為 true

並且,給定以下型別和值,下表中顯示錶達式是有效的並具有指示的語義

[編輯] 圖例

型別 定義
M 佈局對映類
定義
m 型別為(可能帶 const 限定符的)M 的值
i, j (可能帶 const 限定符的)整數包,是 m.extents() 中的多維索引
r typename M​::​extents_type 的(可能帶 const 限定符的)秩索引
d_r (可能帶 const 限定符的)整數包,其中 sizeof...(d_r) == M​::​extents_type​::​rank()true,秩索引 r 處的元素等於 1,所有其他元素等於 0

[編輯] 成員型別

名稱 型別 要求
M::extents_type 類模板 std::extents 的特化
M::index_type typename M::extents_type::index_type
M::rank_type typename M::extents_type::rank_type
M::layout_type 佈局對映策略 MP,其中 typename MP::template mapping<E>M
對於某些 extents 型別 E
LayoutMappingPolicy,其中 MMP 的對映型別

[編輯] 成員函式和運算子

表示式 返回型別 語義
m.extents() const typename M​::​extents_type& 返回關聯多維索引空間的常量引用
m(i...) typename M​::​index_type
m.required_span_size() typename M​::​index_type
  • 如果多維索引空間 m.extents() 的大小不為 0,則返回 1 加上所有 im(i...) 的最大值。
  • 否則,返回 0
m.is_unique() bool 僅當對於所有 ij,如果 (i != j || ...)true,則 m(i...) != m(j...)true 時,才返回 true[注 1]
m.is_exhaustive() bool 僅當對於範圍 [0m.required_span_size()) 中的所有 k,存在一個 i 使得 m(i...) 等於 k 時,才返回 true[注 2]
m.is_strided() bool 僅當對於 m.extents() 的每個秩索引 r,存在一個整數 s_r 使得,對於所有 i,其中 (i + d_r)m.extents() 中的多維索引,m((i + d_r)...) - m(i...) 等於 s_r 時,才返回 true[注 3]
m.stride(r) typename M​::​index_type
  • 前置條件是 m.is_strided()true
  • 返回如上文 m.is_strided() 中定義的,秩索引 r 處的步幅 s_r
M::is_always_unique() bool
  • 僅當對於型別 M 的所有可能物件 mm.is_unique()true 時,才返回 true[注 4]
  • 返回值始終是常量表達式。
M::is_always_exhaustive() bool
  • 僅當對於型別 M 的所有可能物件 mm.is_exhaustive()true 時,才返回 true[注 5]
  • 返回值始終是常量表達式。
M::is_always_strided() bool
  • 僅當對於型別 M 的所有可能物件 mm.is_strided()true 時,才返回 true[注 6]
  • 返回值始終是常量表達式。
  1. 即使滿足條件,對映也可以返回 false。對於某些佈局,高效地確定佈局是否唯一可能不可行。
  2. 同上,但在窮盡佈局的情況下。
  3. 同上,但在帶步幅佈局的情況下。
  4. 即使滿足條件,對映也可以返回 false。對於某些佈局對映,確定每個例項是否唯一可能不可行。
  5. 同上,但在窮盡例項的情況下。
  6. 同上,但在帶步幅例項的情況下。

[編輯] 概念

對於 std::layout_stride::mapping 下使用的約束,定義了以下僅用於說明的概念。

template< class M >

concept /*layout-mapping-alike*/ = requires
{
    requires /*is-extents*/<typename M::extents_type>;
    { M::is_always_strided() }    -> std::same_as<bool>;
    { M::is_always_exhaustive() } -> std::same_as<bool>;
    { M::is_always_unique() }     -> std::same_as<bool>;
    std::bool_constant<M::is_always_strided()>::value;
    std::bool_constant<M::is_always_exhaustive()>::value;
    std::bool_constant<M::is_always_unique()>::value;

};
(僅作說明*)

定義了 LayoutMapping 需求的最小可用性約束。此概念檢查上述謂詞對映特性函式是否存在、是否為常量表達式,以及返回型別是否為 bool

/*is-extents*/<E> 當且僅當 Estd::extents 的特化時,才為 true

[編輯] 標準庫

以下標準庫型別滿足 LayoutMapping 要求

layout_left 的佈局對映
(std::layout_left 的公共成員類模板)[編輯]
layout_right 的佈局對映
(std::layout_right 的公共成員類模板)[編輯]
layout_stride 的佈局對映
(std::layout_stride 的公共成員類模板)[編輯]
layout_left_padded 的佈局對映
(std::layout_left_padded<PaddingValue> 的公共成員類模板)[編輯]
layout_right_padded 的佈局對映
(std::layout_right_padded<PaddingValue> 的公共成員類模板)[編輯]

[編輯] 參閱