3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
10#include <dune/common/hybridutilities.hh>
11#include <dune/common/indices.hh>
13#include <dune/functions/functionspacebases/concepts.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)
49 typename std::enable_if< not models<Concept::HasSizeMethod, VV>(),
int>::type = 0>
50 static auto size(VV&&)
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)
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;
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);
179auto flatVectorView(T& t)
181 return Impl::FlatVectorView<T>(t);
197auto flatVectorView(
const T& t)
199 return Impl::FlatVectorView<const T>(t);
215auto flatVectorView(T&& t)
217 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:30
constexpr auto size(const T &t)
Size query.
Definition: hybridutilities.hh:82
Dune namespace.
Definition: alignedallocator.hh:13