TupleUtility.hpp 1.44 KB
Newer Older
1
2
3
4
#pragma once

#include <tuple>
#include <type_traits>
5
#include <utility>
6

7
8
#include <dune/common/hash.hh>

9
namespace AMDiS
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
  namespace Impl
  {
    // Recursive template code derived from Matthieu M.
    template <class Tuple, std::size_t I = std::tuple_size<Tuple>::value - 1>
    struct HashTupleImpl
    {
      static void apply(size_t& seed, Tuple const& tuple)
      {
        HashTupleImpl<Tuple, I-1>::apply(seed, tuple);
        Dune::hash_combine(seed, std::get<I>(tuple));
      }
    };

    template <class Tuple>
    struct HashTupleImpl<Tuple, 0>
    {
      static void apply(std::size_t& seed, Tuple const& tuple)
      {
        Dune::hash_combine(seed, std::get<0>(tuple));
      }
    };

  } // end namespace Impl

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  template <class Tuple, template <class> class Map>
  struct MapTuple;

  template <class Tuple, template <class> class Map>
  using MapTuple_t = typename MapTuple<Tuple,Map>::type;

  template <class... T, template <class> class Map>
  struct MapTuple<std::tuple<T...>, Map>
  {
    using type = std::tuple<Map<T>...>;
  };

  template <class Indices, template <std::size_t> class Map>
  struct IndexMapTuple;

  template <class Indices, template <std::size_t> class Map>
  using IndexMapTuple_t = typename IndexMapTuple<Indices,Map>::type;

  template <std::size_t... I, template <std::size_t> class Map>
  struct IndexMapTuple<std::index_sequence<I...>, Map>
  {
    using type = std::tuple<Map<I>...>;
  };

59
} // end namespace AMDiS