Dune Core Modules (2.9.0)

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
29 inline friend std::size_t hash_value(const StaticMultiIndex& v) noexcept {
30 return hash_range(v.begin(), v.end());
31 }
32
33};
34
35
36
46template<class size_type>
47class StaticMultiIndex<size_type,1> :
48 public std::array<size_type, 1>
49{
50public:
51
52 static constexpr std::size_t size() { return 1; }
53
54 operator const size_type& () const {
55 return (*this)[0];
56 }
57
58 inline friend std::size_t hash_value(const StaticMultiIndex& v) noexcept {
59 return hash_range(v.begin(), v.end());
60 }
61
62 operator size_type& () {
63 return (*this)[0];
64 }
65
66};
67
68
69
70template<typename Stream, class size_type, std::size_t n>
71inline Stream& operator<<(Stream& stream, const StaticMultiIndex<size_type,n>& c) {
72 for (const auto& ci : c)
73 stream << ci << " ";
74 return stream;
75}
76
77
78
79} // namespace Dune::Functions
80
81template<class size_type, std::size_t n>
82struct std::tuple_size< Dune::Functions::StaticMultiIndex<size_type,n> >
83 : std::integral_constant<std::size_t, n> { };
84
86
87#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)