deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2005 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_table_indices_h
14#define dealii_table_indices_h
15
16
17#include <deal.II/base/config.h>
18
21
22#include <algorithm>
23#include <iterator>
24#include <ostream>
25
26
28
29
40template <int N>
42{
43public:
44 static_assert(N > 0,
45 "TableIndices objects need to represent at least one index.");
46
47
51 constexpr TableIndices() = default;
52
62 template <typename... T>
63 constexpr TableIndices(const T... indices);
64
68 constexpr std::size_t
69 operator[](const unsigned int i) const;
70
74 constexpr std::size_t &
75 operator[](const unsigned int i);
76
80 constexpr bool
81 operator==(const TableIndices<N> &other) const;
82
86 constexpr bool
87 operator!=(const TableIndices<N> &other) const;
88
96
102 template <class Archive>
103 void
104 serialize(Archive &ar, const unsigned int version);
105
106protected:
110 std::size_t indices[N]{};
111};
112
113
114
115/* --------------------- Template and inline functions ---------------- */
116
117template <int N>
118template <typename... T>
119constexpr TableIndices<N>::TableIndices(const T... args)
120 : indices{static_cast<std::size_t>(args)...}
121{
122 static_assert(
124 "Not all of the parameters have integral type!");
125 static_assert(sizeof...(T) == N, "Wrong number of constructor arguments!");
126}
127
128
129template <int N>
130constexpr inline std::size_t
131TableIndices<N>::operator[](const unsigned int i) const
132{
133 AssertIndexRange(i, N);
134 return indices[i];
135}
136
137
138template <int N>
139constexpr inline std::size_t &
140TableIndices<N>::operator[](const unsigned int i)
141{
142 AssertIndexRange(i, N);
143 return indices[i];
144}
145
146
147template <int N>
148constexpr bool
150{
151 return std::equal(std::begin(indices),
152 std::end(indices),
153 std::begin(other.indices));
154}
155
156
157template <int N>
158constexpr bool
160{
161 return !(*this == other);
162}
163
164
165template <int N>
168{
169 std::sort(std::begin(indices), std::end(indices));
170}
171
172
173template <int N>
174template <class Archive>
175inline void
176TableIndices<N>::serialize(Archive &ar, const unsigned int)
177{
178 ar &indices;
179}
180
181
188template <int N>
189std::ostream &
190operator<<(std::ostream &out, const TableIndices<N> &indices)
191{
192 out << '[';
193 for (unsigned int i = 0; i < N; ++i)
194 {
195 out << indices[i];
196 if (i + 1 != N)
197 out << ',';
198 }
199 out << ']';
200
201 return out;
202}
203
204
206
207#endif
std::size_t indices[N]
void serialize(Archive &ar, const unsigned int version)
constexpr std::size_t & operator[](const unsigned int i)
DEAL_II_HOST 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:38
#define DEAL_II_CONSTEXPR
Definition config.h:282
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_HOST
Definition config.h:182
#define AssertIndexRange(index, range)
constexpr char T
STL namespace.
std::ostream & operator<<(std::ostream &out, const TableIndices< N > &indices)