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
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
8#define DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
9
10#include <cstddef>
11#include <array>
12#include <iostream>
13#include <ostream>
14
15#include <dune/common/hash.hh>
16
17
18namespace Dune::Functions {
19
20
21
27template<class size_type, std::size_t n>
29 public std::array<size_type, n>
30{
31public:
32 static constexpr std::size_t size() { return n; }
33 static constexpr std::size_t max_size() { return n; }
34
35 inline friend std::size_t hash_value(const StaticMultiIndex& v) noexcept {
36 return hash_range(v.begin(), v.end());
37 }
38
39};
40
41
42
52template<class size_type>
53class StaticMultiIndex<size_type,1> :
54 public std::array<size_type, 1>
55{
56public:
57
58 static constexpr std::size_t size() { return 1; }
59 static constexpr std::size_t max_size() { return 1; }
60
61
62 operator const size_type& () const {
63 return (*this)[0];
64 }
65
66 inline friend std::size_t hash_value(const StaticMultiIndex& v) noexcept {
67 return hash_range(v.begin(), v.end());
68 }
69
70 operator size_type& () {
71 return (*this)[0];
72 }
73
74};
75
76
77
78template<class size_type, std::size_t n>
79inline std::ostream& operator<<(std::ostream& stream, const StaticMultiIndex<size_type,n>& c) {
80 for (const auto& ci : c)
81 stream << ci << " ";
82 return stream;
83}
84
85
86
87} // namespace Dune::Functions
88
89template<class size_type, std::size_t n>
90struct std::tuple_size< Dune::Functions::StaticMultiIndex<size_type,n> >
91 : std::integral_constant<std::size_t, n> { };
92
94
95#endif // DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
A statically sized MultiIndex type.
Definition: multiindex.hh:30
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 (Nov 24, 23:30, 2024)