XGC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pack.hpp
Go to the documentation of this file.
1 #ifndef PACK_HPP
2 #define PACK_HPP
3 #include "space_settings.hpp"
4 #include "field_list.hpp"
5 
55 template <class T, class... Rest> class Pack : Pack<Rest...> {
56  using Base = Pack<Rest...>;
57  T v_;
58 
59  public:
60 
61  using var_type = typename T::var_type;
62 
74  template<typename Func>
75  KOKKOS_INLINE_FUNCTION void for_each(Func func) {
76  func(v_.v);
77  Base::for_each(func); // Forward to base for recursion
78  }
79 
89  template<typename Func>
90  KOKKOS_INLINE_FUNCTION void for_each_labeled(Func func) const {
91  func(v_);
92  Base::for_each_labeled(func); // Forward to base for recursion
93  }
94 
104  template<FieldName FN>
105  KOKKOS_INLINE_FUNCTION const auto& get() const{
106  if constexpr(T::name==FN){
107  return v_.v;
108  }else{
109  return Base::template get<FN>();
110  }
111  }
112 
122  template<FieldName FN>
123  KOKKOS_INLINE_FUNCTION auto& get() {
124  if constexpr(T::name==FN){
125  return v_.v;
126  }else{
127  return Base::template get<FN>();
128  }
129  }
130 };
131 
140 template <class T> class Pack<T> {
141  T v_;
142 
143  public:
144 
145  using var_type = typename T::var_type;
146 
153  template<typename Func>
154  KOKKOS_INLINE_FUNCTION void for_each(Func func){
155  func(v_.v);
156  }
157 
167  template<typename Func>
168  KOKKOS_INLINE_FUNCTION void for_each_labeled(Func func) const{
169  func(v_);
170  }
171 
181  template<FieldName FN>
182  KOKKOS_INLINE_FUNCTION const auto& get() const{
183  if constexpr(T::name==FN){
184  return v_.v;
185  }else{
186  static_assert(T::name==FN, "No such field name found in this pack");
187  }
188  }
189 
198  template<FieldName FN>
199  KOKKOS_INLINE_FUNCTION auto& get(){
200  if constexpr(T::name==FN){
201  return v_.v;
202  }else{
203  static_assert(T::name==FN, "No such field name found in this pack");
204  }
205  }
206 };
207 
218 template<typename Pack1, typename Pack2>
219 struct PackConcatenator;
220 
231 template<typename... Types1, typename... Types2>
232 struct PackConcatenator<Pack<Types1...>, Pack<Types2...>> {
233  using type = Pack<Types1..., Types2...>;
234 };
235 
244 template<typename Pack1, typename Pack2>
245 using ConcatenatePacks = typename PackConcatenator<Pack1, Pack2>::type;
246 
247 
248 #endif