7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
14#include <dune/common/hybridutilities.hh>
15#include <dune/common/indices.hh>
17#include <dune/functions/functionspacebases/concepts.hh>
28struct FlatVectorBackend
31 template<
class VV,
class Index,
32 std::enable_if_t< models<Concept::HasIndexAccess, VV, Index>(),
int> = 0>
33 static decltype(
auto) getEntry(VV&& v,
const Index& i)
38 template<
class VV,
class Index,
39 std::enable_if_t< not models<Concept::HasIndexAccess, VV, Index>(),
int> = 0>
40 static decltype(
auto) getEntry(VV&& v,
const Index&)
42 return std::forward<VV>(v);
46 std::enable_if_t< models<Concept::HasSizeMethod, VV>(),
int> = 0>
47 static auto size(VV&& v)
53 std::enable_if_t< not models<Concept::HasSizeMethod, VV>(),
int>type = 0>
54 static auto size(VV&&)
63template<
class K,
int n,
int m>
64struct FlatVectorBackend<typename
Dune::FieldMatrix<K, n, m> >
67 template<
class VV,
class Index>
68 static decltype(
auto) getEntry(VV&& v,
const Index& i)
74 static auto size(VV&& v)
82template<
class K, std::
size_t n>
83struct FlatVectorBackend<
std::array<K, n> >
86 template<
class VV,
class Index>
87 static decltype(
auto) getEntry(VV&& v,
const Index& i)
89 const auto innerSize =
decltype(FlatVectorBackend<K>::size(v[0]))::value;
90 return FlatVectorBackend<K>::getEntry(v[i/innerSize], i%innerSize);
94 static auto size(VV&& v)
96 const auto innerSize =
decltype(FlatVectorBackend<K>::size(v[0]))::value;
108 using Backend = FlatVectorBackend<std::decay_t<T>>;
110 FlatVectorView(T& t) :
116 return Backend::size(*t_);
119 template<
class Index>
120 decltype(
auto)
operator[](
const Index& i)
const
122 return Backend::getEntry(*t_, i);
125 template<
class Index>
126 decltype(
auto)
operator[](
const Index& i)
128 return Backend::getEntry(*t_, i);
137class FlatVectorView<T&&>
139 using Backend = FlatVectorBackend<std::decay_t<T>>;
141 FlatVectorView(T&& t) :
147 return Backend::size(t_);
150 template<
class Index>
151 decltype(
auto)
operator[](
const Index& i)
const
153 return Backend::getEntry(t_, i);
156 template<
class Index>
157 decltype(
auto)
operator[](
const Index& i)
159 return Backend::getEntry(t_, i);
183auto flatVectorView(T& t)
185 return Impl::FlatVectorView<T>(t);
201auto flatVectorView(
const T& t)
203 return Impl::FlatVectorView<const T>(t);
219auto flatVectorView(T&& t)
221 return Impl::FlatVectorView<T&&>(std::move(t));
Infrastructure for concepts.
std::integral_constant< std::size_t, i > index_constant
An index constant with value i.
Definition: indices.hh:29
constexpr auto size(const T &t)
Size query.
Definition: hybridutilities.hh:73
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75