Access.hpp 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once

#include <dune/common/typeutilities.hh>
#include <dune/functions/backends/istlvectorbackend.hh>

namespace AMDiS {
namespace Traits {

/// Unified accessor class
struct Access
{
private:
  // if C implements the vector facade interface
  template <class C, class MI>
  auto operator()(C const& c, MI const& mi, Dune::PriorityTag<2>) const
    -> decltype(c.at(mi))
  {
    return c.at(mi);
  }

  // if C supports multi-index access
  template <class C, class MI>
  auto operator()(C const& c, MI const& mi, Dune::PriorityTag<1>) const
    -> decltype(c[mi])
  {
    return c[mi];
  }

  // fallback implementation for simple vectors
  template <class C, class MI>
  auto operator()(C const& c, MI const& mi, Dune::PriorityTag<0>) const
    -> decltype(Dune::Functions::istlVectorBackend(c)[mi])
  {
    return Dune::Functions::istlVectorBackend(c)[mi];
  }

public:
  template <class C, class MI>
  auto operator()(C const& c, MI const& mi) const
  {
    return (*this)(c,mi,Dune::PriorityTag<2>{});
  }
};

}} // end namespace AMDiS::Traits