Reference documentation for deal.II version Git 4abc4a1666 2020-07-04 19:58:34 +0200
\(\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 
99  template <class Archive>
100  void
101  serialize(Archive &ar, const unsigned int version);
102 
103 protected:
107  std::size_t indices[N]{};
108 };
109 
110 
111 
112 /* --------------------- Template and inline functions ---------------- */
113 
114 template <int N>
115 template <typename... T>
116 constexpr TableIndices<N>::TableIndices(const T... args)
117  : indices{static_cast<std::size_t>(args)...}
118 {
120  std::is_integral<T>::value...>::value,
121  "Not all of the parameters have integral type!");
122  static_assert(sizeof...(T) == N, "Wrong number of constructor arguments!");
123 }
124 
125 
126 template <int N>
127 DEAL_II_CONSTEXPR inline std::size_t TableIndices<N>::
128  operator[](const unsigned int i) const
129 {
130  AssertIndexRange(i, N);
131  return indices[i];
132 }
133 
134 
135 template <int N>
136 DEAL_II_CONSTEXPR inline std::size_t &TableIndices<N>::
137  operator[](const unsigned int i)
138 {
139  AssertIndexRange(i, N);
140  return indices[i];
141 }
142 
143 
144 template <int N>
145 constexpr bool
147 {
148  return std::equal(std::begin(indices),
149  std::end(indices),
150  std::begin(other.indices));
151 }
152 
153 
154 template <int N>
155 constexpr bool
157 {
158  return !(*this == other);
159 }
160 
161 
162 template <int N>
163 DEAL_II_CONSTEXPR inline void
165 {
166  std::sort(std::begin(indices), std::end(indices));
167 }
168 
169 
170 template <int N>
171 template <class Archive>
172 inline void
173 TableIndices<N>::serialize(Archive &ar, const unsigned int)
174 {
175  ar &indices;
176 }
177 
178 
185 template <int N>
186 std::ostream &
187 operator<<(std::ostream &out, const TableIndices<N> &indices)
188 {
189  out << '[';
190  for (unsigned int i = 0; i < N; ++i)
191  {
192  out << indices[i];
193  if (i + 1 != N)
194  out << ',';
195  }
196  out << ']';
197 
198  return out;
199 }
200 
201 
203 
204 #endif
constexpr bool operator!=(const TableIndices< N > &other) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1628
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:363
VectorType::value_type * end(VectorType &V)
constexpr std::size_t operator[](const unsigned int i) const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
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:154