7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
13#include <dune/common/concept.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)
49 return Dune::Hybrid::size(v);
53 std::enable_if_t< not models<Concept::HasSizeMethod, VV>(),
int>type = 0>
54 static auto size(VV&&)
56 return Dune::index_constant<1>{};
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)
76 return Dune::index_constant<n*m>{};
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;
97 return Dune::index_constant<n*innerSize>{};
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));
Definition: polynomial.hh:17