ATLAS Offline Software
MakeDerivedVariant.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3  */
4 #ifndef MakeDerivedVariant_h
5 #define MakeDerivedVariant_h
6 
7 namespace {
8 namespace MakeDerivedVariant {
9  template <typename T>
10  static T lvalue(T &&a) { return a;}
11 
12  // dummy method returning a variant which allows for one additional type than the given variant
13  template <class T, typename...Args>
14  constexpr auto extend(const std::variant<Args...> &, const T &) -> std::variant<Args..., T> {
15  std::variant<Args..., T> ret;
16  return ret;
17  }
18 
19  // helper structor to hold the declaration of the variant
20  template <typename TypeHelper, typename VariantType, std::size_t N = std::variant_size_v<VariantType> >
21  struct MakeVariant {
22  using variant_type = decltype( extend(MakeVariant<TypeHelper, VariantType, N-1>::m_val,
23  typename TypeHelper::template type<decltype( lvalue( std::get<N-1>(VariantType{})))> {} ) );
24  variant_type m_val;
25  };
26 
27  // specialisation of above helper structure for N=1 i.e. the variant just allowing T<1>
28  template<typename TypeHelper, typename VariantType>
29  struct MakeVariant<TypeHelper, VariantType,1> {
30  using variant_type = std::variant< typename TypeHelper::template type< decltype( lvalue( std::get<0>(VariantType{}))) > > ;
31  variant_type m_val;
32  };
33 
34 }
35 }
36 #endif
taskman.template
dictionary template
Definition: taskman.py:317
Args
Definition: test_lwtnn_fastgraph.cxx:12
ret
T ret(T t)
Definition: rootspy.cxx:260
MakeDerivedVariant
Definition: MakeDerivedVariant.h:8
a
TList * a
Definition: liststreamerinfos.cxx:10
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78