3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORVIEW_HH
9#include <dune/functions/functionspacebases/concepts.hh>
21struct FlatVectorBackend
24 template<
class VV,
class Index,
25 typename std::enable_if< models<Concept::HasIndexAccess, VV, Index>(),
int>::type = 0>
26 static auto getEntry(VV&& v,
const Index& i)
32 template<
class VV,
class Index,
33 typename std::enable_if< not models<Concept::HasIndexAccess, VV, Index>(),
int>::type = 0>
34 static auto getEntry(VV&& v,
const Index& i)
37 return std::forward<VV>(v);
41 typename std::enable_if< models<Concept::HasSizeMethod, VV>(),
int>::type = 0>
42 static auto size(VV&& v)
49 typename std::enable_if< not models<Concept::HasSizeMethod, VV>(),
int>::type = 0>
50 static std::size_t size(VV&& v)
61template<
class K,
int n,
int m>
62struct FlatVectorBackend<typename
Dune::FieldMatrix<K, n, m> >
65 template<
class VV,
class Index>
66 static auto getEntry(VV&& v,
const Index& i) ->
decltype(v[i/m][i%m])
72 static int size(VV&& v)
84 using Backend = FlatVectorBackend<std::decay_t<T>>;
86 FlatVectorView(T& t) :
92 return Backend::size(*t_);
96 decltype(
auto)
operator[](
const Index& i)
const
98 return Backend::getEntry(*t_, i);
101 template<
class Index>
102 decltype(
auto)
operator[](
const Index& i)
104 return Backend::getEntry(*t_, i);
113class FlatVectorView<T&&>
115 using Backend = FlatVectorBackend<std::decay_t<T>>;
117 FlatVectorView(T&& t) :
123 return Backend::size(t_);
126 template<
class Index>
127 decltype(
auto)
operator[](
const Index& i)
const
129 return Backend::getEntry(t_, i);
132 template<
class Index>
133 decltype(
auto)
operator[](
const Index& i)
135 return Backend::getEntry(t_, i);
159auto flatVectorView(T& t)
161 return Impl::FlatVectorView<T>(t);
177auto flatVectorView(
const T& t)
179 return Impl::FlatVectorView<const T>(t);
195auto flatVectorView(T&& t)
197 return Impl::FlatVectorView<T&&>(std::move(t));
Infrastructure for concepts.
Dune namespace.
Definition: alignedallocator.hh:11