Namespaces
Variants

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

From cppreference.net
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 并用于初始化布局映射。

目录

参数

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 时参与重载决议:
[ 0 , map_  . required_span_size ( ) ) 不是 ptr_ acc_ 可访问范围 (其中 map_ acc_ 取该构造函数调用后的值),则行为未定义。
2) 此重载仅在以下所有条件均为 true 时参与重载决议:
[ 0 , map_  . required_span_size ( ) ) 不是 p acc_ 的可访问范围(其中 map_ acc_ 的值为调用这些构造函数后的值),则行为未定义。
3,4) 这些重载仅在满足以下所有条件时才参与重载决议:
[ 0 , map_  . required_span_size ( ) ) 不是 p acc_ 的可访问范围(其中 map_ acc_ 的值为调用这些构造函数后的值),则行为未定义。
5) 此重载仅在以下所有值为 true 时参与重载决议:
[ 0 , map_  . required_span_size ( ) ) 不是 p acc_ 的可访问范围(其中 map_ acc_ 的值为调用这些构造函数后的值),则行为未定义。
6) 此重载仅当 std:: is_default_constructible_v < accessor_type > true 时参与重载决议。
[ 0 , m. required_span_size ( ) ) 不是 p acc_ 的可访问范围(其中 acc_ 为该构造函数调用后的值),则行为未定义。
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 >
此重载仅在以下所有条件均为 true 时参与重载决议:
若以下任意值为 false ,则程序非良构:
[ 0 , map_  . required_span_size ( ) ) 不是 ptr_ acc_ 的可访问范围(基于该构造函数调用后的 ptr_ map_ acc_ 取值),则行为未定义。

若对于 extents_type 的某个秩索引 r static_extent ( r ) == std:: dynamic_extent
|| static_extent ( r ) == other. extent ( r )
false ,则行为未定义。

(C++26 前)

若对于 extents_type 的某个秩索引 r static_extent ( r ) == std:: dynamic_extent
|| static_extent ( r ) == other. extent ( r )
false

  • 若实现为 强化实现 ,则发生 契约违反 。此外,若契约违反处理程序在“观察”求值语义下返回,则行为未定义。
  • 若实现非强化实现,则行为未定义。
(C++26 起)

示例

参考文献

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

参见