3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
9#include <dune/common/concept.hh>
10#include <dune/common/hybridutilities.hh>
11#include <dune/common/indices.hh>
24struct FlatVectorBackend
27 template<
class VV,
class Index,
28 typename std::enable_if< models<Concept::HasIndexAccess, VV, Index>(),
int>::type = 0>
29 static decltype(
auto) getEntry(VV&& v,
const Index& i)
34 template<
class VV,
class Index,
35 typename std::enable_if< not models<Concept::HasIndexAccess, VV, Index>(),
int>::type = 0>
36 static decltype(
auto) getEntry(VV&& v,
const Index&)
38 return std::forward<VV>(v);
42 typename std::enable_if< models<Concept::HasSizeMethod, VV>(),
int>::type = 0>
43 static auto size(VV&& v)
45 return Dune::Hybrid::size(v);
49 typename std::enable_if< not models<Concept::HasSizeMethod, VV>(),
int>::type = 0>
50 static auto size(VV&&)
52 return Dune::index_constant<1>{};
59template<
class K,
int n,
int m>
60struct FlatVectorBackend<typename
Dune::FieldMatrix<K, n, m> >
63 template<
class VV,
class Index>
64 static decltype(
auto) getEntry(VV&& v,
const Index& i)
70 static auto size(VV&& v)
72 return Dune::index_constant<n*m>{};
78template<
class K, std::
size_t n>
79struct FlatVectorBackend< std::array<K, n> >
82 template<
class VV,
class Index>
83 static decltype(
auto) getEntry(VV&& v,
const Index& i)
85 const auto innerSize =
decltype(FlatVectorBackend<K>::size(v[0]))::value;
86 return FlatVectorBackend<K>::getEntry(v[i/innerSize], i%innerSize);
90 static auto size(VV&& v)
92 const auto innerSize =
decltype(FlatVectorBackend<K>::size(v[0]))::value;
93 return Dune::index_constant<n*innerSize>{};
104 using Backend = FlatVectorBackend<std::decay_t<T>>;
106 FlatVectorView(T& t) :
112 return Backend::size(*t_);
115 template<
class Index>
116 decltype(
auto)
operator[](
const Index& i)
const
118 return Backend::getEntry(*t_, i);
121 template<
class Index>
122 decltype(
auto)
operator[](
const Index& i)
124 return Backend::getEntry(*t_, i);
133class FlatVectorView<T&&>
135 using Backend = FlatVectorBackend<std::decay_t<T>>;
137 FlatVectorView(T&& t) :
143 return Backend::size(t_);
146 template<
class Index>
147 decltype(
auto)
operator[](
const Index& i)
const
149 return Backend::getEntry(t_, i);
152 template<
class Index>
153 decltype(
auto)
operator[](
const Index& i)
155 return Backend::getEntry(t_, i);
181 return Impl::FlatVectorView<T>(t);
199 return Impl::FlatVectorView<const T>(t);
217 return Impl::FlatVectorView<T&&>(std::move(t));
Definition: polynomial.hh:10
auto flatVectorView(T &t)
Create flat vector view of passed mutable container.
Definition: flatvectorview.hh:179