std::mdspan<T,Extents,LayoutPolicy,AccessorPolicy>::mdspan
来自cppreference.com
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()) | (3) | (C++23 起) |
template< class OtherIndexType, std::size_t N > constexpr explicit(N != rank_dynamic()) | (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 > | (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
并以之初始化布局映射。
参数
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>
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>
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>
5) 此重载只有在以下所有值都是 true 时才会参与重载决议:
- std::is_constructible_v<mapping_type, const extents_type&>
- std::is_default_constructible_v<accessor_type>
7) 如果
[
0,
m.required_span_size())
不是 p 和 a 的可访问范围,那么行为未定义。8)explicit 中的表达式等价于 !std::is_convertible_v<const OtherLayoutPolicy::template mapping<OtherExtents>&,
mapping_type>
|| !std::is_convertible_v<const OtherAccessor&, accessor_type>。
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>
如果static_extent(r) == std::dynamic_extent | (C++26 前) |
如果static_extent(r) == std::dynamic_extent | (C++26 起) |
示例
本节未完成 原因:暂无示例 |
引用
- C++23 标准(ISO/IEC 14882:2024):
- 24.7.3.6.2 Constructors [mdspan.mdspan.cons]
参阅
本节未完成 |