Belle II Software  release-05-02-19
EvalVariadic.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tuple>
13 #include <type_traits>
14 
15 namespace Belle2 {
20  namespace TrackFindingCDC {
21 
29  template <class... Ts>
30  static inline void evalVariadic(Ts&& ... expressions __attribute__((unused)))
31  {
32  }
33 
39  struct EvalVariadic {
41  template <class... Ts>
42  explicit EvalVariadic(Ts&& ... expressions __attribute__((unused)))
43  {
44  }
45  };
46 
47 
49  template<class... ATypes>
50  struct FirstTypeImpl {
51  };
52 
54  template<>
55  struct FirstTypeImpl<> {
56  };
57 
59  template<class AType>
60  struct FirstTypeImpl<AType> {
62  using Type = AType;
63  };
64 
66  template<class AType, class... ATypes>
67  struct FirstTypeImpl<AType, ATypes...> {
69  using Type = AType;
70  };
71 
73  template<class... ATypes>
74  using FirstType = typename FirstTypeImpl<ATypes...>::Type;
75 
79  template<class AType, class ATuple>
80  struct GetIndexInTuple {};
81 
83  template<class AType>
84  struct GetIndexInTuple<AType, std::tuple<> > :
85  std::integral_constant<std::size_t, 0> {};
86 
88  template<class AType, class AHeadType, class... ATailTypes>
89  struct GetIndexInTuple<AType, std::tuple<AHeadType, ATailTypes...> > :
90  std::integral_constant < std::size_t, GetIndexInTuple<AType, std::tuple<ATailTypes...> >::value + 1 > {};
91 
93  template<class AType, class... ATailTypes>
94  struct GetIndexInTuple <AType, std::tuple<AType, ATailTypes...> > :
95  std::integral_constant< std::size_t, 0> {};
96 
98  template<class T, class ATuple>
99  using TypeInTuple =
100  std::integral_constant < bool, (GetIndexInTuple<T, ATuple>::value < std::tuple_size<ATuple>::value) >;
101 
102  }
104 }
Belle2::TrackFindingCDC::EvalVariadic::EvalVariadic
EvalVariadic(Ts &&... expressions __attribute__((unused)))
Constructor taking the variadic initalizer list.
Definition: EvalVariadic.h:50
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::FirstTypeImpl
Helper type to take the first type of a variadic sequence of types.
Definition: EvalVariadic.h:58
Belle2::TrackFindingCDC::GetIndexInTuple
Looks up, at which index the given Type can be found in a tuple.
Definition: EvalVariadic.h:88