DUNE PDELab (git)

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
13namespace Dune::Functions {
14
15
16
22template<class size_type, std::size_t n>
24 public std::array<size_type, n>
25{
26public:
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
47template<class size_type>
48class StaticMultiIndex<size_type,1> :
49 public std::array<size_type, 1>
50{
51public:
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
73template<typename Stream, class size_type, std::size_t n>
74inline 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
84template<class size_type, std::size_t n>
85struct std::tuple_size< Dune::Functions::StaticMultiIndex<size_type,n> >
86 : std::integral_constant<std::size_t, n> { };
87
89
90#endif // DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
A statically sized MultiIndex type.
Definition: multiindex.hh:25
Support for calculating hash values of objects.
#define DUNE_DEFINE_HASH(template_args, type)
Defines the required struct specialization to make type hashable via Dune::hash.
Definition: hash.hh:100
#define DUNE_HASH_TYPE(...)
Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH.
Definition: hash.hh:117
#define DUNE_HASH_TEMPLATE_ARGS(...)
Wrapper macro for the template arguments in DUNE_DEFINE_HASH.
Definition: hash.hh:109
Dune namespace.
Definition: alignedallocator.hh:13
std::size_t hash_range(It first, It last)
Hashes all elements in the range [first,last) and returns the combined hash.
Definition: hash.hh:322
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)