Reference documentation for deal.II version Git 87130829be 2021-04-14 12:03:57 -0400
\(\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 - 2020 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 
63  template <typename... T>
64  constexpr TableIndices(const T... indices);
65 
69  DEAL_II_CONSTEXPR std::size_t operator[](const unsigned int i) const;
70 
74  DEAL_II_CONSTEXPR std::size_t &operator[](const unsigned int i);
75 
79  constexpr bool
80  operator==(const TableIndices<N> &other) const;
81 
85  constexpr bool
86  operator!=(const TableIndices<N> &other) const;
87 
93  sort();
94 
100  template <class Archive>
101  void
102  serialize(Archive &ar, const unsigned int version);
103 
104 protected:
108  std::size_t indices[N]{};
109 };
110 
111 
112 
113 /* --------------------- Template and inline functions ---------------- */
114 
115 template <int N>
116 template <typename... T>
117 constexpr TableIndices<N>::TableIndices(const T... args)
118  : indices{static_cast<std::size_t>(args)...}
119 {
121  std::is_integral<T>::value...>::value,
122  "Not all of the parameters have integral type!");
123  static_assert(sizeof...(T) == N, "Wrong number of constructor arguments!");
124 }
125 
126 
127 template <int N>
128 DEAL_II_CONSTEXPR inline std::size_t TableIndices<N>::
129  operator[](const unsigned int i) const
130 {
131  AssertIndexRange(i, N);
132  return indices[i];
133 }
134 
135 
136 template <int N>
137 DEAL_II_CONSTEXPR inline std::size_t &TableIndices<N>::
138  operator[](const unsigned int i)
139 {
140  AssertIndexRange(i, N);
141  return indices[i];
142 }
143 
144 
145 template <int N>
146 constexpr bool
148 {
149  return std::equal(std::begin(indices),
150  std::end(indices),
151  std::begin(other.indices));
152 }
153 
154 
155 template <int N>
156 constexpr bool
158 {
159  return !(*this == other);
160 }
161 
162 
163 template <int N>
164 DEAL_II_CONSTEXPR inline void
166 {
167  std::sort(std::begin(indices), std::end(indices));
168 }
169 
170 
171 template <int N>
172 template <class Archive>
173 inline void
174 TableIndices<N>::serialize(Archive &ar, const unsigned int)
175 {
176  ar &indices;
177 }
178 
179 
186 template <int N>
187 std::ostream &
188 operator<<(std::ostream &out, const TableIndices<N> &indices)
189 {
190  out << '[';
191  for (unsigned int i = 0; i < N; ++i)
192  {
193  out << indices[i];
194  if (i + 1 != N)
195  out << ',';
196  }
197  out << ']';
198 
199  return out;
200 }
201 
202 
204 
205 #endif
constexpr bool operator!=(const TableIndices< N > &other) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1691
constexpr bool operator==(const TableIndices< N > &other) const
constexpr void sort()
void serialize(Archive &ar, const unsigned int version)
static const char T
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:396
VectorType::value_type * end(VectorType &V)
constexpr std::size_t operator[](const unsigned int i) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:395
VectorType::value_type * begin(VectorType &V)
static const char N
constexpr TableIndices()=default
std::size_t indices[N]
#define DEAL_II_CONSTEXPR
Definition: config.h:168