Archivo de encabezado de la biblioteca estándar <mdspan> (C++23)
De cppreference.com
Este archivo de encabezado es parte de la biblioteca de contenedores.
Clases | |
(C++23) |
Una vista no dueña a un array multidimensional. (plantilla de clase) |
(C++23) |
Un descriptor de un espacio de índice multidimensional de algún rango. (plantilla de clase) |
(C++23) |
Política de mapeo de diseño de array multidimensional de columnas principales; la extensión más a la izquierda tiene avance 1 . (clase) |
(C++23) |
Política de mapeo de diseño de array multidimensional de fila principal; la extensión más a la derecha tiene avance 1 . (clase) |
(C++23) |
Una política de mapeo de diseño con avances definidos por el usuario. (clase) |
(C++23) |
Un tipo para acceso indexado a elementos de mdspan . (plantilla de clase) |
(C++26) |
Un especificador de sección que representa un conjunto de índices espaciados regularmente como lo indica un desplazamiento, una extensión y un avance. (plantilla de clase) |
(C++26) |
Un tipo de retorno de las sobrecargas de submdspan_mapping . (plantilla de clase) |
Funciones | |
(C++26) |
Crea nuevas extensiones a partir de las extensiones existentes y los especificadores de sección. (plantilla de función) |
(C++26) |
Devuelve una vista de un subconjunto de un mdspan existente. (plantilla de función) |
Etiquetas | |
(C++26) |
Una etiqueta especificadora de sectores que describe el rango completo de índices en la extensión especificada. (tag) |
[editar] Sinopsis
namespace std { // plantilla de clase extents template<class IndexType, size_t... Extents> class extents; // plantilla de alias dextents template<class IndexType, size_t Rank> using dextents = /* véase descripción */; // mapeo de diseño struct layout_left; struct layout_right; struct layout_stride; // plantilla de clase default_accessor template<class ElementType> class default_accessor; // plantilla de clase mdspan template<class ElementType, class Extents, class LayoutPolicy = layout_right, class AccessorPolicy = default_accessor<ElementType>> class mdspan; // creación de submdspan template<class OffsetType, class LengthType, class StrideType> struct strided_slice; template<class LayoutMapping> struct submdspan_mapping_result; struct full_extent_t { explicit full_extent_t() = default; }; inline constexpr full_extent_t full_extent{}; template<class IndexType, class... Extents, class... SliceSpecifiers> constexpr auto submdspan_extents(const extents<IndexType, Extents...>&, SliceSpecifiers...); // función de plantilla submdspan template<class ElementType, class Extents, class LayoutPolicy, class AccessorPolicy, class... SliceSpecifiers> constexpr auto submdspan( const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy>& src, SliceSpecifiers... slices) -> /* véase descripción */; template<class T> concept /*similar-a-constante-entera*/ = // solo de exposición is_integral_v<decltype(T::value)> && !is_same_v<bool, remove_const_t<decltype(T::value)>> && convertible_to<T, decltype(T::value)> && equality_comparable_with<T, decltype(T::value)> && bool_constant<T() == T::value>::value && bool_constant<static_cast<decltype(T::value)>(T()) == T::value>::value; template<class T, class IndexType> concept /*índice-similar-a-un-par*/ = // solo de exposición /*similar-a-un-par*/<T> && convertible_to<tuple_element_t<0, T>, IndexType> && convertible_to<tuple_element_t<1, T>, IndexType>; }
[editar] Plantilla de clase std::mdspan
namespace std { template<class ElementType, class Extents, class LayoutPolicy, class AccessorPolicy> class mdspan { public: using extents_type = Extents; using layout_type = LayoutPolicy; using accessor_type = AccessorPolicy; using mapping_type = typename layout_type::template mapping<extents_type>; using element_type = ElementType; using value_type = remove_cv_t<element_type>; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using data_handle_type = typename accessor_type::data_handle_type; using reference = typename accessor_type::reference; static constexpr rank_type rank() noexcept { return extents_type::rank(); } static constexpr rank_type rank_dynamic() noexcept { return extents_type::rank_dynamic(); } static constexpr size_t static_extent(rank_type r) noexcept { return extents_type::static_extent(r); } constexpr index_type extent(rank_type r) const noexcept { return extents().extent(r); } // constructores constexpr mdspan(); constexpr mdspan(const mdspan& rhs) = default; constexpr mdspan(mdspan&& rhs) = default; template<class... OtherIndexTypes> constexpr explicit mdspan(data_handle_type ptr, OtherIndexTypes... exts); template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, span<OtherIndexType, N> exts); template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, const array<OtherIndexType, N>& exts); constexpr mdspan(data_handle_type p, const extents_type& ext); constexpr mdspan(data_handle_type p, const mapping_type& m); constexpr mdspan(data_handle_type p, const mapping_type& m, const accessor_type& a); template<class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherAccessorPolicy> constexpr explicit(/* véase descripción */) mdspan(const mdspan<OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessorPolicy>& other); constexpr mdspan& operator=(const mdspan& rhs) = default; constexpr mdspan& operator=(mdspan&& rhs) = default; // miembros template<class... OtherIndexTypes> constexpr reference operator[](OtherIndexTypes... indices) const; template<class OtherIndexType> constexpr reference operator[](span<OtherIndexType, rank()> indices) const; template<class OtherIndexType> constexpr reference operator[](const array<OtherIndexType, rank()>& indices) const; constexpr size_type size() const noexcept; [[nodiscard]] constexpr bool empty() const noexcept; friend constexpr void swap(mdspan& x, mdspan& y) noexcept; constexpr const extents_type& extents() const noexcept { return map_.extents(); } constexpr const data_handle_type& data_handle() const noexcept { return ptr_; } constexpr const mapping_type& mapping() const noexcept { return map_; } constexpr const accessor_type& accessor() const noexcept { return acc_; } static constexpr bool is_always_unique() { return mapping_type::is_always_unique(); } static constexpr bool is_always_exhaustive() { return mapping_type::is_always_exhaustive(); } static constexpr bool is_always_strided() { return mapping_type::is_always_strided(); } constexpr bool is_unique() const { return map_.is_unique(); } constexpr bool is_exhaustive() const { return map_.is_exhaustive(); } constexpr bool is_strided() const { return map_.is_strided(); } constexpr index_type stride(rank_type r) const { return map_.stride(r); } private: accessor_type acc_; // solo de exposición mapping_type map_; // solo de exposición data_handle_type ptr_; // solo de exposición }; template<class CArray> requires(is_array_v<CArray> && rank_v<CArray> == 1) mdspan(CArray&) -> mdspan<remove_all_extents_t<CArray>, extents<size_t, extent_v<CArray, 0>>>; template<class Pointer> requires(is_pointer_v<remove_reference_t<Pointer>>) mdspan(Pointer&&) -> mdspan<remove_pointer_t<remove_reference_t<Pointer>>, extents<size_t>>; template<class ElementType, class... Integrals> requires((is_convertible_v<Integrals, size_t> && ...) && sizeof...(Integrals) > 0) explicit mdspan(ElementType*, Integrals...) -> mdspan<ElementType, dextents<size_t, sizeof...(Integrals)>>; template<class ElementType, class OtherIndexType, size_t N> mdspan(ElementType*, span<OtherIndexType, N>) -> mdspan<ElementType, dextents<size_t, N>>; template<class ElementType, class OtherIndexType, size_t N> mdspan(ElementType*, const array<OtherIndexType, N>&) -> mdspan<ElementType, dextents<size_t, N>>; template<class ElementType, class IndexType, size_t... ExtentsPack> mdspan(ElementType*, const extents<IndexType, ExtentsPack...>&) -> mdspan<ElementType, extents<IndexType, ExtentsPack...>>; template<class ElementType, class MappingType> mdspan(ElementType*, const MappingType&) -> mdspan<ElementType, typename MappingType::extents_type, typename MappingType::layout_type>; template<class MappingType, class AccessorType> mdspan(const typename AccessorType::data_handle_type&, const MappingType&, const AccessorType&) -> mdspan<typename AccessorType::element_type, typename MappingType::extents_type, typename MappingType::layout_type, AccessorType>; }
[editar] Plantilla de clase std::extents
namespace std { template<class IndexType, size_t... Extents> class extents { public: using index_type = IndexType; using size_type = make_unsigned_t<index_type>; using rank_type = size_t; // observadores del espacio de índice multidimensional. static constexpr rank_type rank() noexcept { return sizeof...(Extents); } static constexpr rank_type rank_dynamic() noexcept { return /*índice-dinámico*/(rank()); } static constexpr size_t static_extent(rank_type) noexcept; constexpr index_type extent(rank_type) const noexcept; // constructores constexpr extents() noexcept = default; template<class OtherIndexType, size_t... OtherExtents> constexpr explicit(/* véase descripción */) extents(const extents<OtherIndexType, OtherExtents...>&) noexcept; template<class... OtherIndexTypes> constexpr explicit extents(OtherIndexTypes...) noexcept; template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) extents(span<OtherIndexType, N>) noexcept; template<class OtherIndexType, size_t N> constexpr explicit(N != rank_dynamic()) extents(const array<OtherIndexType, N>&) noexcept; // operadores de comparación template<class OtherIndexType, size_t... OtherExtents> friend constexpr bool operator==(const extents&, const extents<OtherIndexType, OtherExtents...>&) noexcept; // auxiliares solo de exposición constexpr size_t /*fwd-prod-of-extents*/(rank_type) const noexcept; // solo de exposición constexpr size_t /*rev-prod-of-extents*/(rank_type) const noexcept; // solo de exposición template<class OtherIndexType> static constexpr auto /*index-cast*/(OtherIndexType&&) noexcept; // solo de exposición private: static constexpr rank_type /*índice-dinámico*/(rank_type) noexcept; // solo de exposición static constexpr rank_type /*índice-dinámico-inv*/(rank_type) noexcept; // solo de exposición array<index_type, rank_dynamic()>/*dimensiones-dinámicas*/{}; // solo de exposición }; template<class... Integrals> explicit extents(Integrals...) -> /* véase descripción */; }
[editar] Políticas de mapeo de diseño
namespace std { struct layout_left { template<class Extents> class mapping; }; struct layout_right { template<class Extents> class mapping; }; struct layout_stride { template<class Extents> class mapping; }; }
[editar] Plantilla de clase std::layout_left::mapping
namespace std { template<class Extents> class layout_left::mapping { public: using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_left; // constructores constexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&) noexcept; template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping<OtherExtents>&) noexcept; template<class OtherExtents> constexpr explicit(/* véase descripción */) mapping(const layout_right::mapping<OtherExtents>&) noexcept; template<class OtherExtents> explicit(extents_type::rank() > 0) constexpr mapping(const layout_stride::mapping<OtherExtents>&); constexpr mapping& operator=(const mapping&) noexcept = default; // observadores constexpr const extents_type& extents() const noexcept { return extents_; } constexpr index_type required_span_size() const noexcept; template<class... Indices> constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; } static constexpr bool is_always_exhaustive() noexcept { return true; } static constexpr bool is_always_strided() noexcept { return true; } static constexpr bool is_unique() noexcept { return true; } static constexpr bool is_exhaustive() noexcept { return true; } static constexpr bool is_strided() noexcept { return true; } constexpr index_type stride(rank_type) const noexcept; template<class OtherExtents> friend constexpr bool operator==(const mapping&, const mapping<OtherExtents>&) noexcept; private: extents_type extents_{}; // solo de exposición // submdspan mapping specialization template<class... SliceSpecifiers> constexpr auto /*impl-de-mapeo-de-submdspan*/( // solo de exposición SliceSpecifiers... slices) const -> /* véase descripción */; template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping( const mapping& src, SliceSpecifiers... slices) { return src./*impl-de-mapeo-de-submdspan*/(slices...); } }; }
[editar] Plantilla de clase std::layout_right::mapping
namespace std { template<class Extents> class layout_right::mapping { public: using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_right; // constructores constexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&) noexcept; template<class OtherExtents> constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) mapping(const mapping<OtherExtents>&) noexcept; template<class OtherExtents> constexpr explicit(/* véase descripción */) mapping(const layout_left::mapping<OtherExtents>&) noexcept; template<class OtherExtents> constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping<OtherExtents>&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // observadores constexpr const extents_type& extents() const noexcept { return extents_; } constexpr index_type required_span_size() const noexcept; template<class... Indices> constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; } static constexpr bool is_always_exhaustive() noexcept { return true; } static constexpr bool is_always_strided() noexcept { return true; } static constexpr bool is_unique() noexcept { return true; } static constexpr bool is_exhaustive() noexcept { return true; } static constexpr bool is_strided() noexcept { return true; } constexpr index_type stride(rank_type) const noexcept; template<class OtherExtents> friend constexpr bool operator==(const mapping&, const mapping<OtherExtents>&) noexcept; private: extents_type extents_{}; // solo de exposición // especialización de mapeo de submdspan template<class... SliceSpecifiers> constexpr auto /*impl-de-mapeo-de-submdspan*/( // solo de exposición SliceSpecifiers... slices) const -> /* véase descripción */; template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping( const mapping& src, SliceSpecifiers... slices) { return src./*impl-de-mapeo-de-submdspan*/(slices...); } }; }
[editar] Plantilla de clase std::layout_stride::mapping
namespace std { template<class Extents> class layout_stride::mapping { public: using extents_type = Extents; using index_type = typename extents_type::index_type; using size_type = typename extents_type::size_type; using rank_type = typename extents_type::rank_type; using layout_type = layout_stride; private: static constexpr rank_type rank_ = extents_type::rank(); // solo de exposición public: // constructores constexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; template<class OtherIndexType> constexpr mapping(const extents_type&, span<OtherIndexType, rank_>) noexcept; template<class OtherIndexType> constexpr mapping(const extents_type&, const array<OtherIndexType, rank_>&) noexcept; template<class StridedLayoutMapping> constexpr explicit(/* véase descripción */) mapping( const StridedLayoutMapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // observadores constexpr const extents_type& extents() const noexcept { return extents_; } constexpr array<index_type, rank_> strides() const noexcept { return strides_; } constexpr index_type required_span_size() const noexcept; template<class... Indices> constexpr index_type operator()(Indices...) const noexcept; static constexpr bool is_always_unique() noexcept { return true; } static constexpr bool is_always_exhaustive() noexcept { return false; } static constexpr bool is_always_strided() noexcept { return true; } static constexpr bool is_unique() noexcept { return true; } constexpr bool is_exhaustive() const noexcept; static constexpr bool is_strided() noexcept { return true; } constexpr index_type stride(rank_type i) const noexcept { return strides_[i]; } template<class OtherMapping> friend constexpr bool operator==(const mapping&, const OtherMapping&) noexcept; private: extents_type extents_{}; // solo de exposición array<index_type, rank_> strides_{}; // solo de exposición // especialización de mapeo de submdspan template<class... SliceSpecifiers> constexpr auto /*impl-de-mapeo-de-submdspan*/( // solo de exposición SliceSpecifiers... slices) const -> /* véase descripción */; template<class... SliceSpecifiers> friend constexpr auto submdspan_mapping( const mapping& src, SliceSpecifiers... slices) { return src./*impl-de-mapeo-de-submdspan*/(slices...); } }; }
[editar] Auxiliares solo de exposición
template<class T> constexpr bool /*is-extents*/ = false; // solo de exposición template<class SizeType, size_t... Args> constexpr bool /*is-extents*/<extents<IndexType, Args...>> = true; // solo de exposición template<class M> concept /*mapeo-de-diseño-similar*/ = requires { // solo de exposición requires /*is-extents*/<typename M::extents_type>; { M::is_always_strided() } -> same_as<bool>; { M::is_always_exhaustive() } -> same_as<bool>; { M::is_always_unique() } -> same_as<bool>; bool_constant<M::is_always_strided()>::value; bool_constant<M::is_always_exhaustive()>::value; bool_constant<M::is_always_unique()>::value; }; template<class T> constexpr T /*descongelar*/(T val) { return val; } // solo de exposición template</*similar-a-constante-entera*/ T> constexpr auto /*descongelar*/(T) { return T::value; } // solo de exposición template<class IndexType, size_t k, class... SliceSpecifiers> constexpr IndexType /*first_*/(SliceSpecifiers... slices); // solo de exposición template<size_t k, class Extents, class... SliceSpecifiers> // solo de exposición constexpr auto /*last_*/(const Extents& src, SliceSpecifiers... slices); template<class IndexType, size_t N, class... SliceSpecifiers> // solo de exposición constexpr array<IndexType, sizeof...(SliceSpecifiers)> /*índices-fuente*/(const array<IndexType, N>& indices, SliceSpecifiers... slices);
[editar] Plantilla de clase std::default_accessor
namespace std { template<class ElementType> struct default_accessor { using offset_policy = default_accessor; using element_type = ElementType; using reference = ElementType&; using data_handle_type = ElementType*; constexpr default_accessor() noexcept = default; template<class OtherElementType> constexpr default_accessor(default_accessor<OtherElementType>) noexcept; constexpr reference access(data_handle_type p, size_t i) const noexcept; constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept; }; }
[editar] Plantilla de clase std::strided_slice
namespace std { template<class OffsetType, class ExtentType, class StrideType> struct strided_slice { using offset_type = OffsetType; using extent_type = ExtentType; using stride_type = StrideType; [[no_unique_address]] offset_type offset{}; [[no_unique_address]] extent_type extent{}; [[no_unique_address]] stride_type stride{}; }; }
[editar] Plantilla de clase std::submdspan_mapping_result
namespace std { template<class LayoutMapping> struct submdspan_mapping_result { [[no_unique_address]] LayoutMapping mapping = LayoutMapping(); size_t offset{}; }; }
[editar] Referencias
- El estándar C++23 (ISO/IEC 14882:2023):
- 24.7.4 Header
<mdspan>
synopsis [mdspan.syn]
- 24.7.4 Header