Reference documentation for deal.II version 9.4.1
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
table_indices.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2005 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_table_indices_h
17#define dealii_table_indices_h
18
19
20#include <deal.II/base/config.h>
21
24
25#include <algorithm>
26#include <iterator>
27#include <ostream>
28
29
31
32
43template <int N>
45{
46public:
47 static_assert(N > 0,
48 "TableIndices objects need to represent at least one index.");
49
50
54 constexpr TableIndices() = default;
55
65 template <typename... T>
66 constexpr TableIndices(const T... indices);
67
71 constexpr std::size_t
72 operator[](const unsigned int i) const;
73
77 constexpr std::size_t &
78 operator[](const unsigned int i);
79
83 constexpr bool
84 operator==(const TableIndices<N> &other) const;
85
89 constexpr bool
90 operator!=(const TableIndices<N> &other) const;
91
98
104 template <class Archive>
105 void
106 serialize(Archive &ar, const unsigned int version);
107
108protected:
112 std::size_t indices[N]{};
113};
114
115
116
117/* --------------------- Template and inline functions ---------------- */
118
119template <int N>
120template <typename... T>
121constexpr TableIndices<N>::TableIndices(const T... args)
122 : indices{static_cast<std::size_t>(args)...}
123{
125 std::is_integral<T>::value...>::value,
126 "Not all of the parameters have integral type!");
127 static_assert(sizeof...(T) == N, "Wrong number of constructor arguments!");
128}
129
130
131template <int N>
132constexpr inline std::size_t
133TableIndices<N>::operator[](const unsigned int i) const
134{
135 AssertIndexRange(i, N);
136 return indices[i];
137}
138
139
140template <int N>
141constexpr inline std::size_t &
142TableIndices<N>::operator[](const unsigned int i)
143{
144 AssertIndexRange(i, N);
145 return indices[i];
146}
147
148
149template <int N>
150constexpr bool
152{
153 return std::equal(std::begin(indices),
154 std::end(indices),
155 std::begin(other.indices));
156}
157
158
159template <int N>
160constexpr bool
162{
163 return !(*this == other);
164}
165
166
167template <int N>
168DEAL_II_CONSTEXPR inline void
170{
171 std::sort(std::begin(indices), std::end(indices));
172}
173
174
175template <int N>
176template <class Archive>
177inline void
178TableIndices<N>::serialize(Archive &ar, const unsigned int)
179{
180 ar &indices;
181}
182
183
190template <int N>
191std::ostream &
192operator<<(std::ostream &out, const TableIndices<N> &indices)
193{
194 out << '[';
195 for (unsigned int i = 0; i < N; ++i)
196 {
197 out << indices[i];
198 if (i + 1 != N)
199 out << ',';
200 }
201 out << ']';
202
203 return out;
204}
205
206
208
209#endif
std::size_t indices[N]
void serialize(Archive &ar, const unsigned int version)
constexpr std::size_t & operator[](const unsigned int i)
constexpr void sort()
constexpr std::size_t operator[](const unsigned int i) const
constexpr TableIndices(const T... indices)
constexpr TableIndices()=default
constexpr bool operator==(const TableIndices< N > &other) const
constexpr bool operator!=(const TableIndices< N > &other) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_CONSTEXPR
Definition: config.h:177
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
#define AssertIndexRange(index, range)
Definition: exceptions.h:1732
STL namespace.
std::ostream & operator<<(std::ostream &out, const TableIndices< N > &indices)