1// -*-C++ - *- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===---------------------------------------------------------------------===// 9 10/* 11 12// Overall mdspan synopsis 13 14namespace std { 15 // [mdspan.extents], class template extents 16 template<class IndexType, size_t... Extents> 17 class extents; 18 19 // [mdspan.extents.dextents], alias template dextents 20 template<class IndexType, size_t Rank> 21 using dextents = see below; 22 23 // [mdspan.layout], layout mapping 24 struct layout_left; 25 struct layout_right; 26 struct layout_stride; // not implemented yet 27 28 // [mdspan.accessor.default], class template default_accessor 29 template<class ElementType> 30 class default_accessor; 31 32 // [mdspan.mdspan], class template mdspan 33 template<class ElementType, class Extents, class LayoutPolicy = layout_right, 34 class AccessorPolicy = default_accessor<ElementType>> 35 class mdspan; // not implemented yet 36} 37 38// extents synopsis 39 40namespace std { 41 template<class _IndexType, size_t... _Extents> 42 class extents { 43 public: 44 using index_type = _IndexType; 45 using size_type = make_unsigned_t<index_type>; 46 using rank_type = size_t; 47 48 // [mdspan.extents.obs], observers of the multidimensional index space 49 static constexpr rank_type rank() noexcept { return sizeof...(_Extents); } 50 static constexpr rank_type rank_dynamic() noexcept { return dynamic-index(rank()); } 51 static constexpr size_t static_extent(rank_type) noexcept; 52 constexpr index_type extent(rank_type) const noexcept; 53 54 // [mdspan.extents.cons], constructors 55 constexpr extents() noexcept = default; 56 57 template<class _OtherIndexType, size_t... _OtherExtents> 58 constexpr explicit(see below) 59 extents(const extents<_OtherIndexType, _OtherExtents...>&) noexcept; 60 template<class... _OtherIndexTypes> 61 constexpr explicit extents(_OtherIndexTypes...) noexcept; 62 template<class _OtherIndexType, size_t N> 63 constexpr explicit(N != rank_dynamic()) 64 extents(span<_OtherIndexType, N>) noexcept; 65 template<class _OtherIndexType, size_t N> 66 constexpr explicit(N != rank_dynamic()) 67 extents(const array<_OtherIndexType, N>&) noexcept; 68 69 // [mdspan.extents.cmp], comparison operators 70 template<class _OtherIndexType, size_t... _OtherExtents> 71 friend constexpr bool operator==(const extents&, 72 const extents<_OtherIndexType, _OtherExtents...>&) noexcept; 73 74 private: 75 // libcxx note: we do not use an array here, but we need to preserve the as-if behavior 76 // for example the default constructor must zero initialize dynamic extents 77 array<index_type, rank_dynamic()> dynamic-extents{}; // exposition only 78 }; 79 80 template<class... Integrals> 81 explicit extents(Integrals...) 82 -> see below; 83} 84 85// layout_left synopsis 86 87namespace std { 88 template<class Extents> 89 class layout_left::mapping { 90 public: 91 using extents_type = Extents; 92 using index_type = typename extents_type::index_type; 93 using size_type = typename extents_type::size_type; 94 using rank_type = typename extents_type::rank_type; 95 using layout_type = layout_left; 96 97 // [mdspan.layout.right.cons], constructors 98 constexpr mapping() noexcept = default; 99 constexpr mapping(const mapping&) noexcept = default; 100 constexpr mapping(const extents_type&) noexcept; 101 template<class OtherExtents> 102 constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) 103 mapping(const mapping<OtherExtents>&) noexcept; 104 template<class OtherExtents> 105 constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) 106 mapping(const layout_right::mapping<OtherExtents>&) noexcept; 107 template<class OtherExtents> 108 constexpr explicit(extents_type::rank() > 0) 109 mapping(const layout_stride::mapping<OtherExtents>&) noexcept; 110 111 constexpr mapping& operator=(const mapping&) noexcept = default; 112 113 // [mdspan.layout.right.obs], observers 114 constexpr const extents_type& extents() const noexcept { return extents_; } 115 116 constexpr index_type required_span_size() const noexcept; 117 118 template<class... Indices> 119 constexpr index_type operator()(Indices...) const noexcept; 120 121 static constexpr bool is_always_unique() noexcept { return true; } 122 static constexpr bool is_always_exhaustive() noexcept { return true; } 123 static constexpr bool is_always_strided() noexcept { return true; } 124 125 static constexpr bool is_unique() noexcept { return true; } 126 static constexpr bool is_exhaustive() noexcept { return true; } 127 static constexpr bool is_strided() noexcept { return true; } 128 129 constexpr index_type stride(rank_type) const noexcept; 130 131 template<class OtherExtents> 132 friend constexpr bool operator==(const mapping&, const mapping<OtherExtents>&) noexcept; 133 134 private: 135 extents_type extents_{}; // exposition only 136 }; 137} 138 139// layout_right synopsis 140 141namespace std { 142 template<class Extents> 143 class layout_right::mapping { 144 public: 145 using extents_type = Extents; 146 using index_type = typename extents_type::index_type; 147 using size_type = typename extents_type::size_type; 148 using rank_type = typename extents_type::rank_type; 149 using layout_type = layout_right; 150 151 // [mdspan.layout.right.cons], constructors 152 constexpr mapping() noexcept = default; 153 constexpr mapping(const mapping&) noexcept = default; 154 constexpr mapping(const extents_type&) noexcept; 155 template<class OtherExtents> 156 constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) 157 mapping(const mapping<OtherExtents>&) noexcept; 158 template<class OtherExtents> 159 constexpr explicit(!is_convertible_v<OtherExtents, extents_type>) 160 mapping(const layout_left::mapping<OtherExtents>&) noexcept; 161 template<class OtherExtents> 162 constexpr explicit(extents_type::rank() > 0) 163 mapping(const layout_stride::mapping<OtherExtents>&) noexcept; 164 165 constexpr mapping& operator=(const mapping&) noexcept = default; 166 167 // [mdspan.layout.right.obs], observers 168 constexpr const extents_type& extents() const noexcept { return extents_; } 169 170 constexpr index_type required_span_size() const noexcept; 171 172 template<class... Indices> 173 constexpr index_type operator()(Indices...) const noexcept; 174 175 static constexpr bool is_always_unique() noexcept { return true; } 176 static constexpr bool is_always_exhaustive() noexcept { return true; } 177 static constexpr bool is_always_strided() noexcept { return true; } 178 179 static constexpr bool is_unique() noexcept { return true; } 180 static constexpr bool is_exhaustive() noexcept { return true; } 181 static constexpr bool is_strided() noexcept { return true; } 182 183 constexpr index_type stride(rank_type) const noexcept; 184 185 template<class OtherExtents> 186 friend constexpr bool operator==(const mapping&, const mapping<OtherExtents>&) noexcept; 187 188 private: 189 extents_type extents_{}; // exposition only 190 }; 191} 192 193// default_accessor synopsis 194 195namespace std { 196 template<class ElementType> 197 struct default_accessor { 198 using offset_policy = default_accessor; 199 using element_type = ElementType; 200 using reference = ElementType&; 201 using data_handle_type = ElementType*; 202 203 constexpr default_accessor() noexcept = default; 204 template<class OtherElementType> 205 constexpr default_accessor(default_accessor<OtherElementType>) noexcept; 206 constexpr reference access(data_handle_type p, size_t i) const noexcept; 207 constexpr data_handle_type offset(data_handle_type p, size_t i) const noexcept; 208 }; 209} 210 211*/ 212 213#ifndef _LIBCPP_MDSPAN 214#define _LIBCPP_MDSPAN 215 216#include <__config> 217#include <__fwd/mdspan.h> 218#include <__mdspan/default_accessor.h> 219#include <__mdspan/extents.h> 220#include <__mdspan/layout_left.h> 221#include <__mdspan/layout_right.h> 222 223#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 224# pragma GCC system_header 225#endif 226 227#endif // _LIBCPP_MDSPAN 228