DUNE-FUNCTIONS (unstable)

multiindex.hh
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_COMMON_MULTIINDEX_HH
4 #define DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
5 
6 #include <cstddef>
7 #include <array>
8 #include <iostream>
9 
10 #include <dune/common/hash.hh>
11 
12 
13 namespace Dune::Functions {
14 
15 
16 
22 template<class size_type, std::size_t n>
24  public std::array<size_type, n>
25 {
26 public:
27  static constexpr std::size_t size() { return n; }
28  static constexpr std::size_t max_size() { return n; }
29 
30  inline friend std::size_t hash_value(const StaticMultiIndex& v) noexcept {
31  return hash_range(v.begin(), v.end());
32  }
33 
34 };
35 
36 
37 
47 template<class size_type>
48 class StaticMultiIndex<size_type,1> :
49  public std::array<size_type, 1>
50 {
51 public:
52 
53  static constexpr std::size_t size() { return 1; }
54  static constexpr std::size_t max_size() { return 1; }
55 
56 
57  operator const size_type& () const {
58  return (*this)[0];
59  }
60 
61  inline friend std::size_t hash_value(const StaticMultiIndex& v) noexcept {
62  return hash_range(v.begin(), v.end());
63  }
64 
65  operator size_type& () {
66  return (*this)[0];
67  }
68 
69 };
70 
71 
72 
73 template<typename Stream, class size_type, std::size_t n>
74 inline Stream& operator<<(Stream& stream, const StaticMultiIndex<size_type,n>& c) {
75  for (const auto& ci : c)
76  stream << ci << " ";
77  return stream;
78 }
79 
80 
81 
82 } // namespace Dune::Functions
83 
84 template<class size_type, std::size_t n>
85 struct std::tuple_size< Dune::Functions::StaticMultiIndex<size_type,n> >
86  : std::integral_constant<std::size_t, n> { };
87 
88 DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename size_type, std::size_t n),DUNE_HASH_TYPE(Dune::Functions::StaticMultiIndex<size_type,n>))
89 
90 #endif // DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
A statically sized MultiIndex type.
Definition: multiindex.hh:25
Definition: polynomial.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 13, 22:30, 2024)