COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
type_list.hpp
1 // -----------------------------------------------------------------------------
2 // This file is part of COMPASS <https://anr-compass.github.io/compass/>
3 //
4 // Copyright (C) 2011-2023 COMPASS Team <https://github.com/ANR-COMPASS>
5 // All rights reserved.
6 
7 // -----------------------------------------------------------------------------
8 
15 
16 #ifndef CARMA_TYPE_LIST_H
17 #define CARMA_TYPE_LIST_H
18 
19 #include <utility>
20 
21 // Create instantiations for templated functions by keeping their addresses
22 // and therefore forcing the compiler to keep their object code
23 // attribute((unused)) silences the clang/gcc warning
24 template <typename T>
25 void force_keep(T t) {
26  static __attribute__((used)) T x = t;
27 }
28 
29 template <typename...>
31 
32 template <typename Type, typename... Types>
33 struct GenericTypeList<Type, Types...> {
34  using Head = Type;
35  using Tail = GenericTypeList<Types...>;
36 };
37 
38 template <>
39 struct GenericTypeList<> {};
40 
42 
43 template <typename Interfacer, typename TList>
44 struct TypeMap;
45 
46 template <typename Interfacer>
47 struct TypeMap<Interfacer, EmptyList> {
48  template <typename... Args>
49  static void apply(Args &&...) {}
50 };
51 
52 template <typename Interfacer, typename Type,
53  typename... Types //,
54  // typename TList = GenericTypeList<Type,
55  // Types...>, typename Head = typename TList::Head,
56  // typename Tail = typename TList::Tail
57  >
58 struct TypeMap<Interfacer, GenericTypeList<Type, Types...>>
59  : TypeMap<Interfacer, typename GenericTypeList<Type, Types...>::Tail> {
60  using TList = GenericTypeList<Type, Types...>;
61  using Head = typename TList::Head;
62  using Tail = typename TList::Tail;
63 
65 
66  template <typename... Args>
67  static void apply(Args &&... args) {
68  Interfacer::template call<Head>(std::forward<Args>(args)...);
69  Base::template apply(std::forward<Args>(args)...);
70  }
71 };
72 
73 template <typename Interfacer, typename TList, typename... Args>
74 void apply(Args &&... args) {
75  TypeMap<Interfacer, TList>::template apply(std::forward<Args>(args)...);
76 }
77 
78 // template< template <typename> class TemplateT, typename GenericTypeList>
79 // struct TypeMap;
80 
81 // template< template <typename> class TemplateT, typename... Types>
82 // struct TypeMap<TemplateT, GenericTypeList<Types...>> : TemplateT<Types>...
83 // {};
84 
85 #endif // CARMA_TYPE_LIST_H
static void apply(Args &&...)
Definition: type_list.hpp:49