// -*-C++ - *- //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===---------------------------------------------------------------------===// /* // Overall mdspan synopsis namespace std { // [mdspan.extents], class template extents template class extents; // [mdspan.extents.dextents], alias template dextents template using dextents = see below; // [mdspan.layout], layout mapping struct layout_left; struct layout_right; struct layout_stride; // not implemented yet // [mdspan.accessor.default], class template default_accessor template class default_accessor; // [mdspan.mdspan], class template mdspan template> class mdspan; // not implemented yet } // extents synopsis namespace std { template class extents { public: using index_type = _IndexType; using size_type = make_unsigned_t; using rank_type = size_t; // [mdspan.extents.obs], observers of the multidimensional index space static constexpr rank_type rank() noexcept { return sizeof...(_Extents); } static constexpr rank_type rank_dynamic() noexcept { return dynamic-index(rank()); } static constexpr size_t static_extent(rank_type) noexcept; constexpr index_type extent(rank_type) const noexcept; // [mdspan.extents.cons], constructors constexpr extents() noexcept = default; template constexpr explicit(see below) extents(const extents<_OtherIndexType, _OtherExtents...>&) noexcept; template constexpr explicit extents(_OtherIndexTypes...) noexcept; template constexpr explicit(N != rank_dynamic()) extents(span<_OtherIndexType, N>) noexcept; template constexpr explicit(N != rank_dynamic()) extents(const array<_OtherIndexType, N>&) noexcept; // [mdspan.extents.cmp], comparison operators template friend constexpr bool operator==(const extents&, const extents<_OtherIndexType, _OtherExtents...>&) noexcept; private: // libcxx note: we do not use an array here, but we need to preserve the as-if behavior // for example the default constructor must zero initialize dynamic extents array dynamic-extents{}; // exposition only }; template explicit extents(Integrals...) -> see below; } // layout_left synopsis namespace std { template 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; // [mdspan.layout.right.cons], constructors constexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&) noexcept; template constexpr explicit(!is_convertible_v) mapping(const mapping&) noexcept; template constexpr explicit(!is_convertible_v) mapping(const layout_right::mapping&) noexcept; template constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.right.obs], observers constexpr const extents_type& extents() const noexcept { return extents_; } constexpr index_type required_span_size() const noexcept; template 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 friend constexpr bool operator==(const mapping&, const mapping&) noexcept; private: extents_type extents_{}; // exposition only }; } // layout_right synopsis namespace std { template 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; // [mdspan.layout.right.cons], constructors constexpr mapping() noexcept = default; constexpr mapping(const mapping&) noexcept = default; constexpr mapping(const extents_type&) noexcept; template constexpr explicit(!is_convertible_v) mapping(const mapping&) noexcept; template constexpr explicit(!is_convertible_v) mapping(const layout_left::mapping&) noexcept; template constexpr explicit(extents_type::rank() > 0) mapping(const layout_stride::mapping&) noexcept; constexpr mapping& operator=(const mapping&) noexcept = default; // [mdspan.layout.right.obs], observers constexpr const extents_type& extents() const noexcept { return extents_; } constexpr index_type required_span_size() const noexcept; template 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 friend constexpr bool operator==(const mapping&, const mapping&) noexcept; private: extents_type extents_{}; // exposition only }; } // default_accessor synopsis namespace std { template 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 constexpr default_accessor(default_accessor) 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; }; } // mdspan synopsis namespace std { template> class mdspan { public: using extents_type = Extents; using layout_type = LayoutPolicy; using accessor_type = AccessorPolicy; using mapping_type = typename layout_type::template mapping; using element_type = ElementType; using value_type = remove_cv_t; 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); } // [mdspan.mdspan.cons], constructors constexpr mdspan(); constexpr mdspan(const mdspan& rhs) = default; constexpr mdspan(mdspan&& rhs) = default; template constexpr explicit mdspan(data_handle_type ptr, OtherIndexTypes... exts); template constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, span exts); template constexpr explicit(N != rank_dynamic()) mdspan(data_handle_type p, const array& 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 constexpr explicit(see below) mdspan(const mdspan& other); constexpr mdspan& operator=(const mdspan& rhs) = default; constexpr mdspan& operator=(mdspan&& rhs) = default; // [mdspan.mdspan.members], members template constexpr reference operator[](OtherIndexTypes... indices) const; template constexpr reference operator[](span indices) const; template constexpr reference operator[](const array& 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_; // exposition only mapping_type map_; // exposition only data_handle_type ptr_; // exposition only }; template requires(is_array_v && rank_v == 1) mdspan(CArray&) -> mdspan, extents>>; template requires(is_pointer_v>) mdspan(Pointer&&) -> mdspan>, extents>; template requires((is_convertible_v && ...) && sizeof...(Integrals) > 0) explicit mdspan(ElementType*, Integrals...) -> mdspan>; template mdspan(ElementType*, span) -> mdspan>; template mdspan(ElementType*, const array&) -> mdspan>; template mdspan(ElementType*, const extents&) -> mdspan>; template mdspan(ElementType*, const MappingType&) -> mdspan; template mdspan(const typename AccessorType::data_handle_type&, const MappingType&, const AccessorType&) -> mdspan; } */ #ifndef _LIBCPP_MDSPAN #define _LIBCPP_MDSPAN #include <__config> #include <__fwd/mdspan.h> #include <__mdspan/default_accessor.h> #include <__mdspan/extents.h> #include <__mdspan/layout_left.h> #include <__mdspan/layout_right.h> #include <__mdspan/mdspan.h> #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # pragma GCC system_header #endif #endif // _LIBCPP_MDSPAN