5#ifndef DUNE_COMMON_STD_LAYOUT_RIGHT_HH
6#define DUNE_COMMON_STD_LAYOUT_RIGHT_HH
11#include <dune/common/indices.hh>
12#include <dune/common/std/no_unique_address.hh>
13#include <dune/common/std/impl/fwd_layouts.hh>
18template <
class Extents>
21 template <
class>
friend class mapping;
24 using extents_type = Extents;
25 using size_type =
typename extents_type::size_type;
26 using rank_type =
typename extents_type::rank_type;
27 using index_type =
typename extents_type::index_type;
37 constexpr
mapping (const extents_type& e) noexcept
42 template <
class OtherExtents,
43 std::enable_if_t<std::is_constructible_v<extents_type, OtherExtents>,
int> = 0>
44 #if __cpp_conditional_explicit >= 201806L
45 explicit(!std::is_convertible_v<OtherExtents, extents_type>)
48 : extents_(m.extents())
52 template <
class OtherExtents,
class E = extents_type,
53 std::enable_if_t<(E::rank() <= 1),
int> = 0,
54 std::enable_if_t<std::is_constructible_v<extents_type, OtherExtents>,
int> = 0>
55 #
if __cpp_conditional_explicit >= 201806L
56 explicit(!std::is_convertible_v<OtherExtents, extents_type>)
59 : extents_(m.extents())
63 template <
class OtherExtents,
64 std::enable_if_t<std::is_constructible_v<extents_type, OtherExtents>,
int> = 0>
65 #if __cpp_conditional_explicit >= 201806L
66 explicit(extents_type::rank() > 0)
69 : extents_(m.extents())
72 if constexpr(extents_type::rank() > 0) {
74 for (rank_type r = extents_type::rank()-1; r > 0; --r) {
76 prod *= m.extents().extent(r);
86 constexpr const extents_type&
extents () const noexcept {
return extents_; }
87 constexpr index_type required_span_size () const noexcept {
return extents_.product(); }
91 std::enable_if_t<(
sizeof...(Indices) == extents_type::rank()),
int> = 0,
92 std::enable_if_t<(std::is_convertible_v<Indices, index_type> && ...),
int> = 0,
93 std::enable_if_t<(std::is_nothrow_constructible_v<Indices, index_type> && ...),
int> = 0>
96 const std::array indices{index_type(std::move(ii))...};
97 index_type value = indices.front();
98 for (rank_type j = 0; j < extents_type::rank()-1; ++j) {
99 value = indices[j+1] + extents_.extent(j+1) * value;
110 static constexpr bool is_always_unique () noexcept {
return true; }
111 static constexpr bool is_always_exhaustive () noexcept {
return true; }
112 static constexpr bool is_always_strided () noexcept {
return true; }
114 static constexpr bool is_unique () noexcept {
return true; }
115 static constexpr bool is_exhaustive () noexcept {
return true; }
116 static constexpr bool is_strided () noexcept {
return true; }
119 template <
class E = extents_type,
120 std::enable_if_t<(E::rank() > 0),
int> = 0>
121 constexpr index_type
stride (rank_type i)
const noexcept
123 assert(i < extents_type::rank());
125 for (rank_type r = i+1; r < extents_type::rank(); ++r)
130 template <
class OtherExtents>
133 return a.extents_ == b.extents_;
137 DUNE_NO_UNIQUE_ADDRESS extents_type extents_;
Multidimensional index space with dynamic and static extents.
Definition: extents.hh:55
constexpr index_type extent(rank_type r) const noexcept
Return the extent of dimension i
Definition: extents.hh:101
A layout mapping where the leftmost extent has stride 1.
Definition: layout_left.hh:20
A layout mapping where the rightmost extent has stride 1.
Definition: layout_right.hh:20
constexpr index_type operator()() const noexcept
The default offset for rank-0 tensors is 0.
Definition: layout_right.hh:105
constexpr mapping & operator=(const mapping &) noexcept=default
Copy-assignment for the mapping.
constexpr mapping() noexcept=default
The default construction is possible for default constructible extents.
constexpr index_type stride(rank_type i) const noexcept
The stride is the product of the extents E(n)*E(n-1)*...*E(i+1)
Definition: layout_right.hh:121
constexpr mapping(const layout_left::mapping< OtherExtents > &m) noexcept
Construct the mapping from a layout_left.
Definition: layout_right.hh:58
A layout mapping where the strides are user-defined.
Definition: layout_stride.hh:20
constexpr const strides_type & strides() const noexcept
Get the array of all strides.
Definition: layout_stride.hh:128
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:238
Namespace with predefined compile time indices for the range [0,19].
Definition: indices.hh:50
Namespace for features backported from new C++ standards.
Definition: default_accessor.hh:10
A layout where the rightmost extent has stride 1, and strides increase right-to-left as the product o...
Definition: fwd_layouts.hh:30