ThunderEgg  1.0.0
DimensionalArray.h
Go to the documentation of this file.
1 /***************************************************************************
2  * ThunderEgg, a library for solvers on adaptively refined block-structured
3  * Cartesian grids.
4  *
5  * Copyright (c) 2021 Scott Aiton
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  ***************************************************************************/
20 
21 #ifndef THUNDEREGG_DIMENSIONALARRAY_H
22 #define THUNDEREGG_DIMENSIONALARRAY_H
23 
29 namespace ThunderEgg {
38 template<int N, template<int> class T>
40 {
41 private:
46  DimensionalArray<N - 1, T> prev;
50  T<N - 1> t;
51 
52 public:
59  template<int I>
60  T<I>& get()
61  {
62  static_assert(I < N, "invalid index value");
63  if constexpr (I == N - 1) {
64  return t;
65  } else {
66  return prev.template get<I>();
67  }
68  }
75  template<int I>
76  const T<I>& get() const
77  {
78  static_assert(I < N, "invalid index value");
79  if constexpr (I == N - 1) {
80  return t;
81  } else {
82  return prev.template get<I>();
83  }
84  }
85 };
91 template<template<int> class T>
92 class DimensionalArray<1, T>
93 {
94 private:
98  T<0> t;
99 
100 public:
107  template<int I>
108  T<I>& get()
109  {
110  static_assert(I == 0, "invalid index value");
111  return t;
112  }
119  template<int I>
120  const T<I>& get() const
121  {
122  static_assert(I == 0, "invalid index value");
123  return t;
124  }
125 };
126 } // namespace ThunderEgg
127 #endif
ThunderEgg::DimensionalArray::get
T< I > & get()
Get a value at a given index.
Definition: DimensionalArray.h:60
ThunderEgg::DimensionalArray::get
const T< I > & get() const
Get a value at an index.
Definition: DimensionalArray.h:76
ThunderEgg::DimensionalArray< 1, T >::get
T< I > & get()
Get a value at an index.
Definition: DimensionalArray.h:108
ThunderEgg::DimensionalArray
A dimensional array, used for storing templated with and integer. For example a dimensional array of ...
Definition: DimensionalArray.h:39
ThunderEgg::DimensionalArray< 1, T >::get
const T< I > & get() const
Get a value at an index.
Definition: DimensionalArray.h:120
ThunderEgg
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31