Loading [MathJax]/extensions/TeX/newcommand.js
 Reference documentation for deal.II version 9.3.3
\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\}}
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
table_indices.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2005 - 2021 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
63 template <typename... T>
64 constexpr TableIndices(const T... indices);
65
69 constexpr std::size_t operator[](const unsigned int i) const;
70
74 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
94
100 template <class Archive>
101 void
102 serialize(Archive &ar, const unsigned int version);
103
104protected:
108 std::size_t indices[N]{};
109};
110
111
112
113/* --------------------- Template and inline functions ---------------- */
114
115template <int N>
116template <typename... T>
117constexpr 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
127template <int N>
128constexpr inline std::size_t TableIndices<N>::
129 operator[](const unsigned int i) const
130{
132 return indices[i];
133}
134
135
136template <int N>
137constexpr inline std::size_t &TableIndices<N>::operator[](const unsigned int i)
138{
140 return indices[i];
141}
142
143
144template <int N>
145constexpr bool
147{
148 return std::equal(std::begin(indices),
150 std::begin(other.indices));
151}
152
153
154template <int N>
155constexpr bool
157{
158 return !(*this == other);
159}
160
161
162template <int N>
163DEAL_II_CONSTEXPR inline void
165{
166 std::sort(std::begin(indices), std::end(indices));
167}
168
169
170template <int N>
171template <class Archive>
172inline void
173TableIndices<N>::serialize(Archive &ar, const unsigned int)
174{
175 ar &indices;
176}
177
178
185template <int N>
186std::ostream &
187operator<<(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
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 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:402
#define DEAL_II_CONSTEXPR
Definition: config.h:172
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
static const char T
static const char N
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
STL namespace.