std::mdspan<T,Extents,LayoutPolicy,AccessorPolicy>:: 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
(
)
)
|
(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_
|
约束条件与补充信息
- 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 >
[
0
,
map_
.
required_span_size
(
)
)
不是
ptr_
与
acc_
的
可访问范围
(其中
map_
和
acc_
取该构造函数调用后的值),则行为未定义。
- ( 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 >
[
0
,
map_
.
required_span_size
(
)
)
不是
p
与
acc_
的可访问范围(其中
map_
和
acc_
的值为调用这些构造函数后的值),则行为未定义。
- 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 >
[
0
,
map_
.
required_span_size
(
)
)
不是
p
与
acc_
的可访问范围(其中
map_
和
acc_
的值为调用这些构造函数后的值),则行为未定义。
- std:: is_constructible_v < mapping_type, const extents_type & >
- std:: is_default_constructible_v < accessor_type >
[
0
,
map_
.
required_span_size
(
)
)
不是
p
与
acc_
的可访问范围(其中
map_
和
acc_
的值为调用这些构造函数后的值),则行为未定义。
[
0
,
m.
required_span_size
(
)
)
不是
p
与
a
的可访问范围,则行为未定义。
mapping_type >
|| ! std:: is_convertible_v < const OtherAccessor & , accessor_type > 。
-
std::
is_constructible_v
< mapping_type, const OtherLayoutPolicy :: template mapping < OtherExtents > & > - std:: is_default_constructible_v < accessor_type >
- std:: is_constructible_v < data_handle_type, const OtherAccessor :: data_handle_type & >
- std:: is_constructible_v < extents_type, OtherExtents >
[
0
,
map_
.
required_span_size
(
)
)
不是
ptr_
与
acc_
的可访问范围(基于该构造函数调用后的
ptr_
、
map_
和
acc_
取值),则行为未定义。
|
若对于
|
(C++26 前) |
|
若对于
|
(C++26 起) |
示例
|
本节内容不完整
原因:缺少示例 |
参考文献
- C++23 标准 (ISO/IEC 14882:2024):
-
- 24.7.3.6.2 构造函数 [mdspan.mdspan.cons]
参见
| 本节内容尚不完整 |