std::mdspan<T,Extents,LayoutPolicy,AccessorPolicy>::mdspan - cppreference.com (original) (raw)

constexpr mdspan(); (1) (since C++23)
template< class... OtherIndexTypes > constexpr explicit mdspan( data_handle_type p, OtherIndexTypes... exts ); (2) (since 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) (since 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) (since C++23)
constexpr mdspan( data_handle_type p, const extents_type& ext ); (5) (since C++23)
constexpr mdspan( data_handle_type p, const mapping_type& m ); (6) (since C++23)
constexpr mdspan( data_handle_type p, const mapping_type& m, const accessor_type& a ); (7) (since C++23)
template< class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessor > constexpr explicit(/* see below */) mdspan( const mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>& other ); (8) (since C++23)
constexpr mdspan( const mdspan& rhs ) = default; (9) (since C++23)
constexpr mdspan( mdspan&& rhs ) = default; (10) (since C++23)

Constructs an mdspan, optionally using user-supplied data handle p, layout mapping m, and accessor a. If extents exts or ext are supplied, they are converted to extents_type and used to initialize the layout mapping.

Contents

[edit] Parameters

p - a handle to the underlying data
m - a layout mapping
a - an accessor
ext - a std::extents object
exts - represents a multi-dimensional extents
other - another mdspan to convert from
rhs - another mdspan to copy or move from

[edit] Effects

For the data members listed in the table below:

Overload Initializer for...
ptr_ map_ acc_
(1) (empty)
(2) std::move(p) extents_type (static_cast<index_type> (std::move(exts))...) (empty)
(3) extents_type(exts)
(4)
(5) ext
(6) m
(7) a
(8) other.ptr_ other.map_ other.acc_

[edit] Constraints and supplement information

If [​0​, _[map](../mdspan.html#map "cpp/container/mdspan")_ .required_span_size()) is not an accessible range of _[ptr](../mdspan.html#ptr "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ for the values of _[map](../mdspan.html#map "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ after the invocation of this constructor, the behavior is undefined.

If [​0​, _[map](../mdspan.html#map "cpp/container/mdspan")_ .required_span_size()) is not an accessible range of p and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ for the values of _[map](../mdspan.html#map "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ after the invocation of these constructors, the behavior is undefined.

If [​0​, _[map](../mdspan.html#map "cpp/container/mdspan")_ .required_span_size()) is not an accessible range of p and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ for the values of _[map](../mdspan.html#map "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ after the invocation of these constructors, the behavior is undefined.

If [​0​, _[map](../mdspan.html#map "cpp/container/mdspan")_ .required_span_size()) is not an accessible range of p and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ for the values of _[map](../mdspan.html#map "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ after the invocation of these constructors, the behavior is undefined.

If [​0​, m.required_span_size()) is an accessible range of p and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ for the value of _[acc](../mdspan.html#acc "cpp/container/mdspan")_ after the invocation of this constructor, the behavior is undefined.

  1. If [​0​, m.required_span_size()) is not an accessible range of p and a, the behavior is undefined.

  2. The expression inside explicit is equivalent to std::is\_convertible\_v<const OtherLayoutPolicy::template mapping<OtherExtents>&,
    mapping_type>
    || std::is\_convertible\_v<const OtherAccessor&, accessor_type>.

If [​0​, _[map](../mdspan.html#map "cpp/container/mdspan")_ .required_span_size()) is not an accessible range of _[ptr](../mdspan.html#ptr "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ for the values of _[ptr](../mdspan.html#ptr "cpp/container/mdspan")_, _[map](../mdspan.html#map "cpp/container/mdspan")_ and _[acc](../mdspan.html#acc "cpp/container/mdspan")_ after the invocation of this constructor, the behavior is undefined.

| If static_extent(r) == std::dynamic_extent || static_extent(r) == other.extent(r) is false for some rank index r of extents_type, the behavior is undefined. | (until C++26) | | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | | If static_extent(r) == std::dynamic_extent || static_extent(r) == other.extent(r) is false for some rank index r of extents_type: If the implementation is hardened, a contract violation occurs. Moreover, if the contract-violation handler returns under “observe” evaluation semantic, the behavior is undefined. If the implementation is not hardened, the behavior is undefined. | (since C++26) |

[edit] Example

[edit] References

[edit] See also