Reference documentation for deal.II version GIT 29f9da0a34 2023-12-07 10:00: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\}}\)
table_indices.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2005 - 2023 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 
43 template <int N>
45 {
46 public:
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  sort();
99 
105  template <class Archive>
106  void
107  serialize(Archive &ar, const unsigned int version);
108 
109 protected:
113  std::size_t indices[N]{};
114 };
115 
116 
117 
118 /* --------------------- Template and inline functions ---------------- */
119 
120 template <int N>
121 template <typename... T>
122 constexpr TableIndices<N>::TableIndices(const T... args)
123  : indices{static_cast<std::size_t>(args)...}
124 {
125  static_assert(
126  internal::TemplateConstraints::all_true<std::is_integral_v<T>...>::value,
127  "Not all of the parameters have integral type!");
128  static_assert(sizeof...(T) == N, "Wrong number of constructor arguments!");
129 }
130 
131 
132 template <int N>
133 constexpr inline std::size_t
134 TableIndices<N>::operator[](const unsigned int i) const
135 {
136  AssertIndexRange(i, N);
137  return indices[i];
138 }
139 
140 
141 template <int N>
142 constexpr inline std::size_t &
143 TableIndices<N>::operator[](const unsigned int i)
144 {
145  AssertIndexRange(i, N);
146  return indices[i];
147 }
148 
149 
150 template <int N>
151 constexpr bool
153 {
154  return std::equal(std::begin(indices),
155  std::end(indices),
156  std::begin(other.indices));
157 }
158 
159 
160 template <int N>
161 constexpr bool
163 {
164  return !(*this == other);
165 }
166 
167 
168 template <int N>
171 {
172  std::sort(std::begin(indices), std::end(indices));
173 }
174 
175 
176 template <int N>
177 template <class Archive>
178 inline void
179 TableIndices<N>::serialize(Archive &ar, const unsigned int)
180 {
181  ar &indices;
182 }
183 
184 
191 template <int N>
192 std::ostream &
193 operator<<(std::ostream &out, const TableIndices<N> &indices)
194 {
195  out << '[';
196  for (unsigned int i = 0; i < N; ++i)
197  {
198  out << indices[i];
199  if (i + 1 != N)
200  out << ',';
201  }
202  out << ']';
203 
204  return out;
205 }
206 
207 
209 
210 #endif
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition: operator.h:165
std::size_t indices[N]
void serialize(Archive &ar, const unsigned int version)
constexpr std::size_t & operator[](const unsigned int i)
constexpr std::size_t operator[](const unsigned int i) const
constexpr TableIndices(const T... indices)
constexpr DEAL_II_HOST void sort()
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:477
#define DEAL_II_CONSTEXPR
Definition: config.h:207
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
#define AssertIndexRange(index, range)
Definition: exceptions.h:1888
static const char T
static const char N
VectorType::value_type * begin(VectorType &V)
VectorType::value_type * end(VectorType &V)
#define DEAL_II_HOST
Definition: numbers.h:46