dune-common  2.11
mdarray.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_COMMON_STD_MDARRAY_HH
6 #define DUNE_COMMON_STD_MDARRAY_HH
7 
8 #include <algorithm>
9 #include <array>
10 #include <memory>
11 #include <vector>
12 #include <span>
13 #include <tuple>
14 #include <type_traits>
15 #if __has_include(<version>)
16  #include <version>
17 #endif
18 
19 #include <dune/common/indices.hh>
25 
26 namespace Dune::Std {
27 
66 template <class Element, class Extents, class LayoutPolicy = Std::layout_right,
67  class Container = std::vector<Element>>
68 class mdarray
69 {
70  template <class,class,class,class> friend class mdarray;
71 
72  static_assert(std::is_object_v<Element>);
73  static_assert(!std::is_abstract_v<Element>);
74  static_assert(!std::is_array_v<Element>);
75  static_assert(std::is_same_v<Element, typename Container::value_type>);
76 
77 public:
78  using element_type = Element;
79  using extents_type = Extents;
80  using layout_type = LayoutPolicy;
81  using container_type = Container;
82 
84  using mapping_type = typename layout_type::template mapping<extents_type>;
85 
86  using index_type = typename extents_type::index_type;
87  using size_type = typename extents_type::size_type;
88  using rank_type = typename extents_type::rank_type;
89 
92 
93  using pointer = decltype(std::to_address(std::declval<container_type>().begin()));
94  using reference = typename container_type::reference;
95  using const_pointer = decltype(std::to_address(std::declval<container_type>().cbegin()));
96  using const_reference = typename container_type::const_reference;
97 
98  static_assert(std::is_constructible_v<mapping_type, extents_type>);
99 
100 private:
101  // helper function to construct the container
102  template <class C, class... Args>
103  static constexpr auto construct_container (Args&&... args)
104  -> decltype(Impl::ContainerConstructionTraits<C>::construct(std::forward<Args>(args)...))
105  {
106  return Impl::ContainerConstructionTraits<C>::construct(std::forward<Args>(args)...);
107  }
108 
109 public:
112 
114  template <class E = extents_type, class C = container_type, class M = mapping_type,
115  std::enable_if_t<(E::rank_dynamic() != 0), int> = 0,
116  std::enable_if_t<std::is_default_constructible_v<C>, int> = 0,
117  std::enable_if_t<std::is_default_constructible_v<M>, int> = 0>
118  constexpr mdarray ()
119  : container_{}
120  , mapping_{}
121  {}
122 
123 
124  // -------------------------------------
125  // constructors from extents or mappings
126 
127 
129  template <class... IndexTypes,
130  std::enable_if_t<(... && std::is_convertible_v<IndexTypes,index_type>), int> = 0,
131  std::enable_if_t<std::is_constructible_v<extents_type,IndexTypes...>, int> = 0,
132  std::enable_if_t<(... && std::is_nothrow_constructible_v<index_type,IndexTypes>), int> = 0>
133  explicit constexpr mdarray (IndexTypes... exts)
134  : mdarray(extents_type(index_type(std::move(exts))...))
135  {}
136 
138  explicit constexpr mdarray (const extents_type& e)
139  : mdarray(mapping_type(e))
140  {}
141 
143  template <class C = container_type,
144  decltype(construct_container<C>(std::declval<std::size_t>()), bool{}) = true>
145  explicit constexpr mdarray (const mapping_type& m)
146  : container_(construct_container<C>(m.required_span_size()))
147  , mapping_(m)
148  {}
149 
150 
151  // ---------------------------------------
152  // constructors with a given initial value
153 
155  constexpr mdarray (const extents_type& e, const value_type& v)
156  : mdarray(mapping_type(e), v)
157  {}
158 
160  template <class C = container_type,
161  decltype(construct_container<C>(std::declval<std::size_t>(),std::declval<const value_type&>()), bool{}) = true>
162  constexpr mdarray (const mapping_type& m, const value_type& v)
163  : container_(construct_container<C>(m.required_span_size(), v))
164  , mapping_(m)
165  {}
166 
167 
168  // -----------------------------------
169  // constructors with a given container
170 
172  template <class E = extents_type,
173  std::enable_if_t<std::is_constructible_v<mapping_type,const E&>, int> = 0>
174  constexpr mdarray (const E& e, const container_type& c)
175  : container_(c)
176  , mapping_(e)
177  {}
178 
180  template <class E = extents_type,
181  std::enable_if_t<std::is_constructible_v<mapping_type,const E&>, int> = 0>
182  constexpr mdarray (const E& e, container_type&& c)
183  : container_(std::move(c))
184  , mapping_(e)
185  {}
186 
188  constexpr mdarray (const mapping_type& m, const container_type& c)
189  : container_(c)
190  , mapping_(m)
191  {}
192 
194  constexpr mdarray (const mapping_type& m, container_type&& c)
195  : container_(std::move(c))
196  , mapping_(m)
197  {}
198 
199 
200  // -----------------------
201  // converting constructors
202 
204  template <class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class OtherContainer,
205  std::enable_if_t<std::is_constructible_v<Container,const OtherContainer&>, int> = 0,
206  std::enable_if_t<std::is_constructible_v<extents_type,OtherExtents>, int> = 0,
207  std::enable_if_t<std::is_constructible_v<mapping_type,const typename OtherLayoutPolicy::template mapping<OtherExtents>&>, int> = 0>
208  #if __cpp_conditional_explicit >= 201806L
209  explicit(
210  !std::is_convertible_v<const typename OtherLayoutPolicy::template mapping<OtherExtents>&, mapping_type> ||
211  !std::is_convertible_v<const OtherContainer&, container_type>)
212  #endif
214  : container_(other.container_)
215  , mapping_(other.mapping_)
216  {}
217 
219  template <class OtherElementType, class OtherExtents, class OtherLayoutPolicy, class Accessor,
220  std::enable_if_t<std::is_constructible_v<value_type,typename Accessor::reference>, int> = 0,
221  std::enable_if_t<std::is_assignable_v<value_type&, typename Accessor::reference>, int> = 0,
222  std::enable_if_t<std::is_constructible_v<mapping_type, const typename OtherLayoutPolicy::template mapping<OtherExtents>&>, int> = 0,
223  decltype(construct_container<container_type>(std::declval<std::size_t>()), bool{}) = true>
224  #if __cpp_conditional_explicit >= 201806L
225  explicit(
226  !std::is_convertible_v<const typename OtherLayoutPolicy::template mapping<OtherExtents>&, mapping_type> ||
227  !std::is_convertible_v<typename Accessor::reference, value_type>)
228  #endif
230  : container_(construct_container<container_type>(other.size()))
231  , mapping_(other.mapping())
232  {
233  init_from_mdspan(other);
234  }
235 
236 
237  // ----------------------------
238  // constructors with allocators
239 
241  template <class Alloc,
242  std::enable_if_t<std::is_constructible_v<container_type, std::size_t, Alloc>, int> = 0>
243  constexpr mdarray (const extents_type& e, const Alloc& a)
244  : mdarray(mapping_type(e), a)
245  {}
246 
248  template <class Alloc,
249  std::enable_if_t<std::is_constructible_v<container_type, std::size_t, Alloc>, int> = 0>
250  constexpr mdarray (const mapping_type& m, const Alloc& a)
251  : container_(m.required_span_size(), a)
252  , mapping_(m)
253  {}
254 
256  template <class Alloc>
257  constexpr mdarray (const extents_type& e, const value_type& v, const Alloc& a)
258  : mdarray(mapping_type(e), v, a)
259  {}
260 
262  template <class Alloc,
263  std::enable_if_t<std::is_constructible_v<container_type, std::size_t, value_type, Alloc>, int> = 0>
264  constexpr mdarray (const mapping_type& m, const value_type& v, const Alloc& a)
265  : container_(m.required_span_size(), v, a)
266  , mapping_(m)
267  {}
268 
270  template <class Alloc,
271  std::enable_if_t<std::is_constructible_v<container_type, container_type, Alloc>, int> = 0>
272  constexpr mdarray (const extents_type& e, const container_type& c, const Alloc& a)
273  : container_(c, a)
274  , mapping_(e)
275  {}
276 
278  template <class Alloc,
279  std::enable_if_t<std::is_constructible_v<container_type, container_type, Alloc>, int> = 0>
280  constexpr mdarray (const extents_type& e, container_type&& c, const Alloc& a)
281  : container_(std::move(c), a)
282  , mapping_(e)
283  {}
284 
286  template <class Alloc,
287  std::enable_if_t<std::is_constructible_v<container_type, container_type, Alloc>, int> = 0>
288  constexpr mdarray (const mapping_type& m, const container_type& c, const Alloc& a)
289  : container_(c, a)
290  , mapping_(m)
291  {}
292 
294  template <class Alloc,
295  std::enable_if_t<std::is_constructible_v<container_type, container_type, Alloc>, int> = 0>
296  constexpr mdarray (const mapping_type& m, container_type&& c, const Alloc& a)
297  : container_(std::move(c), a)
298  , mapping_(m)
299  {}
300 
302  template <class V, class E, class L, class C, class Alloc,
303  std::enable_if_t<std::is_constructible_v<container_type, C, Alloc>, int> = 0>
304  #if __cpp_conditional_explicit >= 201806L
305  explicit(
306  !std::is_convertible_v<const typename L::template mapping<E>&, mapping_type> ||
307  !std::is_convertible_v<const C&, container_type>)
308  #endif
309  constexpr mdarray (const mdarray<V,E,L,C>& other, const Alloc& a) noexcept
310  : container_(other.container_, a)
311  , mapping_(other.mapping_)
312  {}
313 
315  template <class V, class E, class L, class A, class Alloc,
316  class C = container_type,
317  class Al = typename C::allocator_type,
318  std::enable_if_t<std::is_constructible_v<C, std::size_t, Alloc>, int> = 0>
319  #if __cpp_conditional_explicit >= 201806L
320  explicit(
321  !std::is_convertible_v<const typename L::template mapping<E>&, mapping_type> ||
322  !std::is_convertible_v<typename A::reference, value_type> ||
323  !std::is_convertible_v<Alloc, Al>)
324  #endif
325  constexpr mdarray (const mdspan<V,E,L,A>& other, const Alloc& a)
326  : container_(other.size(), a)
327  , mapping_(other.mapping_)
328  {
329  init_from_mdspan(other);
330  }
331 
333 
334 private:
335 
336  template <class V, class E, class L, class A, class... Indices>
337  void init_from_mdspan (const mdspan<V,E,L,A>& other, Indices... ii)
338  {
339  constexpr rank_type pos = sizeof...(Indices);
340  if constexpr(pos < rank()) {
341  for (typename E::index_type i = 0; i < other.extent(pos); ++i)
342  init_from_mdspan(other,ii...,i);
343  } else {
344  using I = std::array<typename E::index_type,E::rank()>;
345  container_[mapping_(index_type(ii)...)] = other[I{ii...}];
346  }
347  }
348 
349 public:
350 
353 
360  template <class... Indices,
361  std::enable_if_t<(sizeof...(Indices) == extents_type::rank()), int> = 0,
362  std::enable_if_t<(... && std::is_convertible_v<Indices,index_type>), int> = 0>
363  constexpr reference operator() (Indices... indices)
364  {
365  return container_[mapping_(index_type(std::move(indices))...)];
366  }
367 
372  template <class... Indices,
373  std::enable_if_t<(sizeof...(Indices) == extents_type::rank()), int> = 0,
374  std::enable_if_t<(... && std::is_convertible_v<Indices,index_type>), int> = 0>
375  constexpr const_reference operator() (Indices... indices) const
376  {
377  return container_[mapping_(index_type(std::move(indices))...)];
378  }
379 
380 
381 #if __cpp_multidimensional_subscript >= 202110L
382 
384  template <class... Indices,
385  std::enable_if_t<(sizeof...(Indices) == extents_type::rank()), int> = 0,
386  std::enable_if_t<(... && std::is_convertible_v<Indices,index_type>), int> = 0>
387  constexpr reference operator[] (Indices... indices)
388  {
389  return container_[mapping_(index_type(std::move(indices))...)];
390  }
391 
393  template <class... Indices,
394  std::enable_if_t<(sizeof...(Indices) == extents_type::rank()), int> = 0,
395  std::enable_if_t<(... && std::is_convertible_v<Indices,index_type>), int> = 0>
396  constexpr const_reference operator[] (Indices... indices) const
397  {
398  return container_[mapping_(index_type(std::move(indices))...)];
399  }
400 
401 #else
402 
405  template <class Index, class E = extents_type,
406  std::enable_if_t<std::is_convertible_v<Index,index_type>, int> = 0,
407  std::enable_if_t<(E::rank() == 1), int> = 0>
408  constexpr reference operator[] (Index index)
409  {
410  return container_[mapping_(index_type(std::move(index)))];
411  }
412 
415  template <class Index, class E = extents_type,
416  std::enable_if_t<std::is_convertible_v<Index,index_type>, int> = 0,
417  std::enable_if_t<(E::rank() == 1), int> = 0>
418  constexpr const_reference operator[] (Index index) const
419  {
420  return container_[mapping_(index_type(std::move(index)))];
421  }
422 
423 #endif
424 
425 
427  template <class Index,
428  std::enable_if_t<std::is_convertible_v<const Index&, index_type>, int> = 0>
429  constexpr reference operator[] (std::span<Index,extents_type::rank()> indices)
430  {
431  return unpackIntegerSequence([&](auto... ii) -> reference {
432  return container_[mapping_(index_type(indices[ii])...)]; },
433  std::make_index_sequence<extents_type::rank()>{});
434  }
435 
437  template <class Index,
438  std::enable_if_t<std::is_convertible_v<const Index&, index_type>, int> = 0>
439  constexpr const_reference operator[] (std::span<Index,extents_type::rank()> indices) const
440  {
441  return unpackIntegerSequence([&](auto... ii) -> const_reference {
442  return container_[mapping_(index_type(indices[ii])...)]; },
443  std::make_index_sequence<extents_type::rank()>{});
444  }
445 
447  template <class Index,
448  std::enable_if_t<std::is_convertible_v<const Index&, index_type>, int> = 0>
449  constexpr reference operator[] (const std::array<Index,extents_type::rank()>& indices)
450  {
451  return std::apply([&](auto... ii) -> reference {
452  return container_[mapping_(index_type(ii)...)]; }, indices);
453  }
454 
456  template <class Index,
457  std::enable_if_t<std::is_convertible_v<const Index&, index_type>, int> = 0>
458  constexpr const_reference operator[] (const std::array<Index,extents_type::rank()>& indices) const
459  {
460  return std::apply([&](auto... ii) -> const_reference {
461  return container_[mapping_(index_type(ii)...)]; }, indices);
462  }
463 
465 
466 
468  constexpr const extents_type& extents () const noexcept { return mapping_.extents(); }
469 
471  constexpr const mapping_type& mapping () const noexcept { return mapping_; }
472 
474  constexpr const container_type& container () const noexcept { return container_; }
475 
482  constexpr container_type&& extract_container () && noexcept { return std::move(container_); }
483 
484 
487 
489  static constexpr rank_type rank () noexcept { return extents_type::rank(); }
490 
492  static constexpr rank_type rank_dynamic () noexcept { return extents_type::rank_dynamic(); }
493 
495  static constexpr std::size_t static_extent (rank_type r) noexcept { return extents_type::static_extent(r); }
496 
498  constexpr index_type extent (rank_type r) const noexcept { return extents().extent(r); }
499 
501  constexpr size_type size () const noexcept
502  {
503  size_type s = 1;
504  for (rank_type r = 0; r < rank(); ++r)
505  s *= extent(r);
506  return s;
507  }
508 
510  constexpr std::size_t container_size () const { return container_.size(); }
511 
513  [[nodiscard]] constexpr bool empty () const noexcept { return size() == 0; }
514 
516  constexpr index_type stride (rank_type r) const { return mapping().stride(r); };
517 
519 
520 
521  static constexpr bool is_always_unique () noexcept { return mapping_type::is_always_unique(); }
522  static constexpr bool is_always_exhaustive () noexcept { return mapping_type::is_always_exhaustive(); }
523  static constexpr bool is_always_strided () noexcept { return mapping_type::is_always_strided(); }
524 
525  constexpr bool is_unique () const noexcept { return mapping_.is_unique(); }
526  constexpr bool is_exhaustive () const noexcept { return mapping_.is_exhaustive(); }
527  constexpr bool is_strided () const noexcept { return mapping_.is_strided(); }
528 
529 
532 
534  constexpr pointer container_data () noexcept { return std::to_address(container_.begin()); }
535 
537  constexpr const_pointer container_data () const noexcept { return std::to_address(container_.begin()); }
538 
540 
541 
542  friend constexpr void swap (mdarray& x, mdarray& y) noexcept
543  {
544  using std::swap;
545  swap(x.container_, y.container_);
546  swap(x.mapping_, y.mapping_);
547  }
548 
549 
552 
553  friend constexpr bool operator== (const mdarray& lhs, const mdarray& rhs) noexcept
554  {
555  return lhs.mapping() == rhs.mapping() && lhs.container() == rhs.container();
556  }
557 
559 
562 
564  template <class V, class E, class L, class A,
565  std::enable_if_t<std::is_assignable_v<mdspan<V,E,L,A>, mdspan_type>, int> = 0>
566  constexpr operator mdspan<V,E,L,A> ()
567  {
568  return mdspan_type(container_data(), mapping());
569  }
570 
572  template <class V, class E, class L, class A,
573  std::enable_if_t<std::is_assignable_v<mdspan<V,E,L,A>, const_mdspan_type>, int> = 0>
574  constexpr operator mdspan<V,E,L,A> () const
575  {
577  }
578 
580  template <class AccessorPolicy = Std::default_accessor<element_type>,
581  std::enable_if_t<
582  std::is_assignable_v<mdspan_type, mdspan<element_type,extents_type,layout_type,AccessorPolicy>>, int> = 0>
584  to_mdspan (const AccessorPolicy& a = AccessorPolicy{})
585  {
587  }
588 
590  template <class AccessorPolicy = Std::default_accessor<const element_type>,
591  std::enable_if_t<
592  std::is_assignable_v<const_mdspan_type, mdspan<const element_type,extents_type,layout_type,AccessorPolicy>>, int> = 0>
593  constexpr mdspan<const element_type,extents_type,layout_type,AccessorPolicy>
594  to_mdspan (const AccessorPolicy& a = AccessorPolicy{}) const
595  {
597  }
598 
599 protected:
602 };
603 
607 
608 template <class IndexType, std::size_t... exts, class Container>
609 mdarray (const Std::extents<IndexType, exts...>&, const Container&)
610  -> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
611 
612 template <class Mapping, class Container>
613 mdarray (const Mapping&, const Container&)
615 
616 template <class IndexType, std::size_t... exts, class Container>
617 mdarray (const Std::extents<IndexType, exts...>&, Container&&)
618  -> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
619 
620 template <class Mapping, class Container>
621 mdarray (const Mapping&, Container&&)
623 
624 template <class Element, class Extents, class Layout, class Accessor>
626  -> mdarray<std::remove_cv_t<Element>, Extents, Layout>;
627 
628 template <class IndexType, std::size_t... exts, class Container, class Alloc>
629 mdarray (const Std::extents<IndexType, exts...>&, const Container&, const Alloc&)
630  -> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
631 
632 template <class Mapping, class Container, class Alloc>
633 mdarray (const Mapping&, const Container&, const Alloc&)
635 
636 template <class IndexType, std::size_t... exts, class Container, class Alloc>
637 mdarray (const Std::extents<IndexType, exts...>&, Container&&, const Alloc&)
638  -> mdarray<typename Container::value_type, Std::extents<IndexType, exts...>, layout_right, Container>;
639 
640 template <class Mapping, class Container, class Alloc>
641 mdarray (const Mapping&, Container&&, const Alloc&)
643 
644 template <class Element, class Extents, class Layout, class Accessor, class Alloc>
646  -> mdarray<std::remove_cv_t<Element>, Extents, Layout>;
647 
649 
653 
654 template <class Element, class Extents, class Layout, class Container>
656  typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::element_type,
657  typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::extents_type,
658  typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::layout_type,
659  typename decltype(std::declval<mdarray<Element, Extents, Layout, Container>>().to_mdspan())::accessor_type>;
660 
662 
663 } // end namespace Dune::Std
664 
665 #endif // DUNE_COMMON_STD_MDARRAY_HH
static constexpr std::size_t static_extent(rank_type r) noexcept
Number of elements in the r&#39;th dimension of the tensor.
Definition: mdarray.hh:495
constexpr mdarray(const mapping_type &m, const container_type &c, const Alloc &a)
Construct from layout mapping, container and allocator.
Definition: mdarray.hh:288
Namespace for features backported from new C++ standards.
Definition: algorithm.hh:19
container_type container_
Definition: mdarray.hh:600
constexpr mdarray(const mapping_type &m, container_type &&c, const Alloc &a)
Construct from layout mapping, container and allocator.
Definition: mdarray.hh:296
A multi-dimensional non-owning array view.
Definition: mdspan.hh:64
constexpr reference operator[](Index index)
Access specified element at position [i0] For a rank one mdarray, the operator[i] is added to support...
Definition: mdarray.hh:408
constexpr mdspan< element_type, extents_type, layout_type, AccessorPolicy > to_mdspan(const AccessorPolicy &a=AccessorPolicy{})
Conversion function to mdspan.
Definition: mdarray.hh:584
Element element_type
Definition: mdarray.hh:78
decltype(std::to_address(std::declval< container_type >().cbegin())) const_pointer
Definition: mdarray.hh:95
constexpr std::size_t container_size() const
Size of the underlying container.
Definition: mdarray.hh:510
decltype(auto) constexpr unpackIntegerSequence(F &&f, [[maybe_unused]] std::integer_sequence< I, i... > sequence)
Unpack an std::integer_sequence<I,i...> to std::integral_constant<I,i>...
Definition: indices.hh:124
#define DUNE_NO_UNIQUE_ADDRESS
Definition: no_unique_address.hh:24
constexpr index_type extent(rank_type r) const noexcept
Number of elements in the r&#39;th dimension of the tensor.
Definition: mdarray.hh:498
element_type value_type
Definition: mdarray.hh:83
friend constexpr void swap(mdarray &x, mdarray &y) noexcept
Definition: mdarray.hh:542
constexpr mdarray(IndexTypes... exts)
Construct from the dynamic extents.
Definition: mdarray.hh:133
constexpr mdarray(const mapping_type &m, const value_type &v, const Alloc &a)
Construct from layout mapping, initial value and allocator.
Definition: mdarray.hh:264
constexpr size_type size() const noexcept
Size of the multi-dimensional index space.
Definition: mdarray.hh:501
constexpr mdarray(const mapping_type &m, container_type &&c)
Construct from layout mapping and the storage container.
Definition: mdarray.hh:194
constexpr bool is_strided() const noexcept
Definition: mdarray.hh:527
constexpr mdarray(const E &e, container_type &&c)
Construct from extents and the storage container.
Definition: mdarray.hh:182
friend constexpr bool operator==(const mdarray &lhs, const mdarray &rhs) noexcept
Definition: mdarray.hh:553
constexpr bool empty() const noexcept
Check whether the index space is empty.
Definition: mdarray.hh:513
typename layout_type::template mapping< extents_type > mapping_type
Definition: mdarray.hh:84
Multidimensional index space with dynamic and static extents.This class template represents a multidi...
Definition: extents.hh:54
constexpr reference operator()(Indices... indices)
Access element at position (i0,i1,...)
Definition: mdarray.hh:363
constexpr mdarray(const mdspan< OtherElementType, OtherExtents, OtherLayoutPolicy, Accessor > &other)
Converting constructor from mdspan.
Definition: mdarray.hh:229
I i
Definition: hybridmultiindex.hh:328
Utilities for reduction like operations on ranges.
static constexpr bool is_always_strided() noexcept
Definition: mdarray.hh:523
constexpr const container_type & container() const noexcept
The underlying storage container.
Definition: mdarray.hh:474
constexpr mdarray(const extents_type &e, const container_type &c, const Alloc &a)
Construct from extents, container and allocator.
Definition: mdarray.hh:272
A layout where the rightmost extent has stride 1, and strides increase right-to-left as the product o...
Definition: fwd_layouts.hh:29
Container container_type
Definition: mdarray.hh:81
mdspan< const element_type, extents_type, layout_type > const_mdspan_type
Definition: mdarray.hh:91
typename container_type::reference reference
Definition: mdarray.hh:94
constexpr mdarray()
A default constructor; needed only if the constructor for dynamic extents does not apply...
Definition: mdarray.hh:118
Extents extents_type
Definition: mdarray.hh:79
constexpr const extents_type & extents() const noexcept
Number of elements in all dimensions of the array,.
Definition: mdarray.hh:468
constexpr size_type size() const noexcept
The number of elements accessible by this multi-dimensional span.
Definition: mdspan.hh:279
static constexpr bool is_always_unique() noexcept
Definition: mdarray.hh:521
constexpr mdarray(const extents_type &e, container_type &&c, const Alloc &a)
Construct from extents, container and allocator.
Definition: mdarray.hh:280
constexpr const mapping_type & mapping() const noexcept
Index mapping of a layout policy.
Definition: mdarray.hh:471
constexpr mdarray(const extents_type &e)
Construct from the extents of the array.
Definition: mdarray.hh:138
typename extents_type::rank_type rank_type
Definition: mdarray.hh:88
decltype(std::to_address(std::declval< container_type >().begin())) pointer
Definition: mdarray.hh:93
constexpr mdarray(const mapping_type &m, const container_type &c)
Construct from layout mapping and the storage container.
Definition: mdarray.hh:188
constexpr mdarray(const extents_type &e, const Alloc &a)
Construct from the extents of the array and allocator.
Definition: mdarray.hh:243
constexpr index_type stride(rank_type r) const
The stride along the specified dimension.
Definition: mdarray.hh:516
static constexpr rank_type rank_dynamic() noexcept
Number of dimension with dynamic size.
Definition: mdarray.hh:492
constexpr const_pointer container_data() const noexcept
Direct access to the underlying const data in the container.
Definition: mdarray.hh:537
mdspan(CArray &) -> mdspan< std::remove_all_extents_t< CArray >, Std::extents< std::size_t, std::extent_v< CArray, 0 >>>
typename extents_type::index_type index_type
Definition: mdarray.hh:86
constexpr mdarray(const mapping_type &m, const Alloc &a)
Construct from the layout mapping of the array and allocator.
Definition: mdarray.hh:250
mdspan< element_type, extents_type, layout_type > mdspan_type
Definition: mdarray.hh:90
void swap(T &v1, T &v2, bool mask)
Definition: simd.hh:472
constexpr mdarray(const extents_type &e, const value_type &v, const Alloc &a)
Construct from extents, initial value and allocator.
Definition: mdarray.hh:257
STL namespace.
Get the &#39;const&#39; version of a reference to a mutable object.
Definition: genericiterator.hh:86
DUNE_NO_UNIQUE_ADDRESS mapping_type mapping_
Definition: mdarray.hh:601
typename extents_type::size_type size_type
Definition: mdarray.hh:87
constexpr bool is_unique() const noexcept
Definition: mdarray.hh:525
An owning multi-dimensional array analog of mdspan.
Definition: mdarray.hh:68
LayoutPolicy layout_type
Definition: mdarray.hh:80
constexpr pointer container_data() noexcept
Direct access to the underlying data in the container.
Definition: mdarray.hh:534
constexpr mdspan< const element_type, extents_type, layout_type, AccessorPolicy > to_mdspan(const AccessorPolicy &a=AccessorPolicy{}) const
Conversion function to mdspan.
Definition: mdarray.hh:594
typename container_type::const_reference const_reference
Definition: mdarray.hh:96
span(T(&)[N]) -> span< T, N >
static constexpr rank_type rank() noexcept
Number of dimensions of the array.
Definition: mdarray.hh:489
constexpr index_type extent(rank_type r) const noexcept
Number of elements in the r&#39;th dimension of the tensor.
Definition: mdspan.hh:276
constexpr bool is_exhaustive() const noexcept
Definition: mdarray.hh:526
constexpr auto to_address(T &&p) noexcept
Obtain the address represented by p without forming a reference to the object pointed to by p...
Definition: memory.hh:47
constexpr mdarray(const E &e, const container_type &c)
Construct from extents and the storage container.
Definition: mdarray.hh:174
constexpr mdarray(const extents_type &e, const value_type &v)
Construct from extents and initial value.
Definition: mdarray.hh:155
static constexpr bool is_always_exhaustive() noexcept
Definition: mdarray.hh:522
constexpr container_type && extract_container() &&noexcept
Move the container out of the mdarray.
Definition: mdarray.hh:482