dune-functions 2.9.0
multiindex.hh
Go to the documentation of this file.
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
85DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename size_type, std::size_t n),DUNE_HASH_TYPE(Dune::Functions::StaticMultiIndex<size_type,n>))
86
87#endif // DUNE_FUNCTIONS_COMMON_MULTIINDEX_HH
Definition: polynomial.hh:10
Definition: polynomial.hh:11
Stream & operator<<(Stream &stream, const StaticMultiIndex< size_type, n > &c)
Definition: multiindex.hh:71
A statically sized MultiIndex type.
Definition: multiindex.hh:25
static constexpr std::size_t size()
Definition: multiindex.hh:27
friend std::size_t hash_value(const StaticMultiIndex &v) noexcept
Definition: multiindex.hh:29
static constexpr std::size_t size()
Definition: multiindex.hh:52
friend std::size_t hash_value(const StaticMultiIndex &v) noexcept
Definition: multiindex.hh:58