dune-functions  2.5.1
flatvectorbackend.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORBACKEND_HH
4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORBACKEND_HH
5 
6 
7 #include <dune/common/concept.hh>
8 
10 
11 
12 
13 
14 namespace Dune {
15 namespace Functions {
16 
17 
18 
19 template<class V>
21 {
22 
23  template<class VV, class Index,
24  typename std::enable_if< models<Concept::HasIndexAccess, VV, Index>(), int>::type = 0>
25  static auto getEntry(VV&& v, const Index& i)
26  ->decltype(v[i])
27  {
28  return v[i];
29  }
30 
31  template<class VV, class Index,
32  typename std::enable_if< not models<Concept::HasIndexAccess, VV, Index>(), int>::type = 0>
33  static auto getEntry(VV&& v, const Index& i)
34  ->decltype(v)
35  {
36  return std::forward<VV>(v);
37  }
38 
39  template<class VV,
40  typename std::enable_if< models<Concept::HasSizeMethod, VV>(), int>::type = 0>
41  static auto size(VV&& v)
42  ->decltype(v.size())
43  {
44  return v.size();
45  }
46 
47  template<class VV,
48  typename std::enable_if< not models<Concept::HasSizeMethod, VV>(), int>::type = 0>
49  static std::size_t size(VV&& v)
50  {
51  return 1;
52  }
53 
54 };
55 
56 
57 
58 
59 
60 template<class K, int n, int m>
62 {
63 
64  template<class VV, class Index>
65  static auto getEntry(VV&& v, const Index& i) -> decltype(v[i/m][i%m])
66  {
67  return v[i/m][i%m];
68  }
69 
70  template<class VV>
71  static int size(VV&& v)
72  {
73  return n*m;
74  }
75 };
76 
77 
78 } // namespace Dune::Functions
79 } // namespace Dune
80 
81 
82 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_FLATVECTORBACKEND_HH
static auto getEntry(VV &&v, const Index &i) -> decltype(v)
Definition: flatvectorbackend.hh:33
static std::size_t size(VV &&v)
Definition: flatvectorbackend.hh:49
static auto getEntry(VV &&v, const Index &i) -> decltype(v[i/m][i%m])
Definition: flatvectorbackend.hh:65
static int size(VV &&v)
Definition: flatvectorbackend.hh:71
Definition: polynomial.hh:7
static auto size(VV &&v) -> decltype(v.size())
Definition: flatvectorbackend.hh:41
Definition: flatvectorbackend.hh:20
static auto getEntry(VV &&v, const Index &i) -> decltype(v[i])
Definition: flatvectorbackend.hh:25