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