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

来自cppreference.com
 
 
 
 
<tbody> </tbody>
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。如果提供了尺度 extsext,那么将它们转换到 extents_type 并以之初始化布局映射。

参数

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

效果

对于下表中列出的数据成员:

  • 如果对应的初始化器为空,那么该数据成员会被值初始化
  • 如果对应的初始化器不为空,那么该数据成员会以该初始化器被直接非列表初始化
 重载  ...对应的初始化器
ptr_ map_ acc_
(1) (空)
(2) std::move(p) extents_type
(static_cast<index_type>
(std::move(exts))...)
(空)
(3) extents_type(exts)
(4)
(5) ext
(6) m
(7) a
(8) other.ptr_ other.map_ other.acc_

约束和补充信息

1) 此重载只有在以下所有值都是 true 时才会参与重载决议:
  • rank_dynamic() > 0
  • std::is_default_constructible_v<data_handle_type>
  • std::is_default_constructible_v<mapping_type>
  • std::is_default_constructible_v<accessor_type>
如果在调用此构造函数后 [0map_ .required_span_size()) 对于 map_acc_ 的值不是 ptr_acc_可访问范围,那么行为未定义。
2) 此重载只有在以下所有值都是 true 时才会参与重载决议:
  • (std::is_convertible_v<OtherIndexTypes, index_type> && ...)
  • (std::is_nothrow_constructible<index_type, OtherIndexTypes> && ...)
  • sizeof...(OtherIndexTypes) == rank() || sizeof...(OtherIndexTypes) == rank_dynamic()
  • std::is_constructible_v<mapping_type, extents_type>
  • std::is_default_constructible_v<accessor_type>
如果在调用此构造函数后 [0map_ .required_span_size()) 对于 map_acc_ 的值不是 pacc_ 的可访问范围,那么行为未定义。
3,4) 这些重载只有在以下所有值都是 true 时才会参与重载决议:
  • std::is_convertible_v<const OtherIndexType&, index_type>
  • std::is_nothrow_constructible_v<index_type, const OtherIndexType&>
  • N == rank() || N == rank_dynamic()
  • std::is_constructible_v<mapping_type, extents_type>
  • std::is_default_constructible_v<accessor_type>
如果在调用这些构造函数后 [0map_ .required_span_size()) 对于 map_acc_ 的值不是 pacc_ 的可访问范围,那么行为未定义。
5) 此重载只有在以下所有值都是 true 时才会参与重载决议:
  • std::is_constructible_v<mapping_type, const extents_type&>
  • std::is_default_constructible_v<accessor_type>
如果在调用此构造函数后 [0map_ .required_span_size()) 对于 map_acc_ 的值不是 pacc_ 的可访问范围,那么行为未定义。
6) 此重载只有在 std::is_default_constructible_v<accessor_type>true 时才会参与重载决议。
如果在调用此构造函数后 [0m.required_span_size()) 对于 acc_ 的值不是 pacc_ 的可访问范围,那么行为未定义。
7) 如果[0m.required_span_size()) 不是 pa 的可访问范围,那么行为未定义。
8) explicit 中的表达式等价于 !std::is_convertible_v<const OtherLayoutPolicy::template mapping<OtherExtents>&,
mapping_type>
|| !std::is_convertible_v<const OtherAccessor&, accessor_type>
此重载只有在以下所有值都是 true 时才会参与重载决议:
  • std::is_constructible_v
    <mapping_type, const OtherLayoutPolicy::template mapping<OtherExtents>&>
  • std::is_default_constructible_v<accessor_type>
如果以下任意值是 false ,那么程序非良构:
  • std::is_constructible_v<data_handle_type, const OtherAccessor::data_handle_type&>
  • std::is_constructible_v<extents_type, OtherExtents>
如果在调用此构造函数后 [0map_ .required_span_size()) 对于 ptr_map_acc_ 的值不是 ptr_acc_ 的可访问范围,那么行为未定义。

如果static_extent(r) == std::dynamic_extent
|| static_extent(r) == other.extent(r)
对于 extents_type 的某个秩索引 rfalse,那么行为未定义。

(C++26 前)

如果static_extent(r) == std::dynamic_extent
|| static_extent(r) == other.extent(r)
对于 extents_type 的某个秩索引 rfalse,那么:

  • 如果实现是硬化实现,那么就会发生契约违背。并且契约违背处理函数在“观察”求值语义下返回时行为未定义。
  • 如果实现不是硬化实现,那么行为未定义。
(C++26 起)

示例

引用

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

参阅