std::mdspan<T,Extents,LayoutPolicy,AccessorPolicy>::mdspan

来自cppreference.com
< cpp‎ | container‎ | mdspan
 
 
 
 
constexpr mdspan();
(1) (C++23 起)
template< class... OtherIndexTypes >
    constexpr explicit mdspan( data_handle_type p, OtherIndexTypes... exts );
(2) (C++23 起)
template< class OtherIndexType, std::size_t N >

    constexpr explicit(N != rank_dynamic())

        mdspan( data_handle_type p, std::span<OtherIndexType, N> exts );
(3) (C++23 起)
template< class OtherIndexType, std::size_t N >

    constexpr explicit(N != rank_dynamic())

        mdspan( data_handle_type p, const std::array<OtherIndexType, N>& exts );
(4) (C++23 起)
constexpr mdspan( data_handle_type p, const extents_type& ext );
(5) (C++23 起)
constexpr mdspan( data_handle_type p, const mapping_type& m );
(6) (C++23 起)
constexpr mdspan( data_handle_type p, const mapping_type& m,
                  const accessor_type& a );
(7) (C++23 起)
template< class OtherElementType, class OtherExtents,

          class OtherLayoutPolicy, class OtherAccessor >
    constexpr explicit(/* 见下文 */)
        mdspan( const mdspan<OtherElementType, OtherExtents,

                             OtherLayoutPolicy, OtherAccessor>& other );
(8) (C++23 起)
constexpr mdspan( const mdspan& rhs ) = default;
(9) (C++23 起)
constexpr mdspan( mdspan&& rhs ) = default;
(10) (C++23 起)

构造一个 mdspan,可选地使用用户提供的数据句柄 p、布局映射 m 和访问器 a。若提供了尺度 exts 或 ext,则将它们转换为 extents_type 并以之初始化布局映射。

1) 构造空 mdspan。值初始化 ptr_、map_ 和 acc_。
  • 如果对于调用此构造函数后的 map_ 和 acc_ 值,[​0​, map_.required_span_size()) 不是 ptr_ 和 acc_ 上的可访问范围,则其行为未定义。
  • 此重载只有在
2) 在由 p 所代表的底层数据上,以 exts... 所表示的尺度创建 mdspan。值初始化 acc_,以 std::move(p) 对 ptr_,并以 extents_type(static_cast<index_type>(std::move(exts))...) 对 map_ 进行直接非列表初始化。
  • 如果对于调用此构造函数后的 map_ 和 acc_ 值,[​0​, map_.required_span_size()) 不是 ptr_ 和 acc_ 上的可访问范围,则其行为未定义。
  • 令 N 为 sizeof...(OtherIndexTypes)。此重载只有在
3,4) 在由 p 所代表的底层数据上,以包 exts 所表示的尺度创建 mdspan。值初始化 acc_,以 std::move(p) 对 ptr_,并以 extents_type(exts) 对 map_ 进行直接非列表初始化。
  • 如果对于调用此构造函数后的 map_ 和 acc_ 值,[​0​, map_.required_span_size()) 不是 ptr_ 和 acc_ 上的可访问范围,则其行为未定义。
  • 此重载只有在
5) 在由 p 所代表的底层数据上,以 ext 所表示的尺度创建 mdspan。值初始化 acc_,以 std::move(p) 对 ptr_,并以 exts 对 map_ 进行直接非列表初始化。
  • 如果对于调用此构造函数后的 map_ 和 acc_ 值,[​0​, map_.required_span_size()) 不是 p 和 acc_ 上的可访问范围,则其行为未定义。
  • 此重载只有在
6) 在由 p 所代表的底层数据上,以布局映射 m 创建 mdspan。值初始化 acc_,以 std::move(p) 对 ptr_,并以 m 对 map_ 进行直接非列表初始化。
  • 如果对于调用此构造函数后的 acc_ 值,[​0​, m.required_span_size()) 不是 p 和 acc_ 上的可访问范围,则其行为未定义。
  • 此重载只有在 std::is_default_constructible_v<accessor_type> 为 true 时才会参与重载决议。
7) 在由 p 所代表的底层数据上,以布局映射 m 和访问器 a 创建 mdspan。以 std::move(p) 对 ptr_,以 m 对 map_,并以 a 对 acc_ 进行直接非列表初始化。
  • 如果调用此构造函数后,[​0​, m.required_span_size()) 不是 p 和 a 上的可访问范围,则其行为未定义。
8) 从另一 mdspan 的转换构造函数。以 other.ptr_ 对 ptr_,以 other.map_ 对 map_,并以 other.acc_ 对 acc_ 进行直接非列表初始化。
  • 以下情况下其行为未定义:
  • 对于调用此构造函数后的 map_ 和 acc_ 值,[​0​, map_.required_span_size()) 不是 ptr_ 和 acc_ 上的可访问范围,或者
  • 对于 extents_type 的每个秩索引 r,   extents_type::static_extent(r) == std::dynamic_extent
    || extents_type::static_extent(r) == other.extent(r)
    为 false。
  • 此重载只有在
  • 以下情况下程序非良构:

参数

p - 底层数据的句柄
m - 布局映射
a - 访问器
ext - std::extents 对象
exts - 表示一种多维尺度
other - 要从之转换的另一 mdspan
rhs - 要从之复制或移动的另一 mdspan

示例

引用

  • C++23 标准(ISO/IEC 14882:2024):
  • 24.7.3.6.2 Constructors [mdspan.mdspan.cons]

参阅