CMS 3D CMS Logo

produce_helpers.h
Go to the documentation of this file.
1 #ifndef Framework_produce_helpers_h
2 #define Framework_produce_helpers_h
3 // -*- C++ -*-
4 //
5 // Package: Framework
6 // Class : produce_helpers
7 //
16 //
17 // Author: Chris Jones
18 // Created: Fri Apr 15 10:25:20 EDT 2005
19 //
20 
21 // system include files
22 #include <memory>
23 #include <optional>
24 // user include files
25 
26 namespace edm::eventsetup {
27 
28  namespace produce {
29  struct Null;
30  }
31 
32  template <typename FromT, typename ToT>
33  void moveFromTo(FromT& iFrom, ToT& iTo) {
34  iTo = std::move(iFrom);
35  }
36 
37  namespace produce {
38  struct Null {};
39  template <typename T>
40  struct EndList {
41  static_assert(
42  (not std::is_pointer_v<T>),
43  "use std::shared_ptr or std::unique_ptr to hold EventSetup data products, do not use bare pointers");
44  using tail_type = T;
45  using head_type = Null;
46  };
47  template <typename T>
48  struct product_traits {
49  using type = T;
50  };
51  template <typename T>
52  struct product_traits<T*> {
53  using type = EndList<T*>;
54  };
55  template <typename T>
58  };
59  template <typename T>
60  struct product_traits<std::shared_ptr<T>> {
62  };
63  template <typename T>
64  struct product_traits<std::optional<T>> {
66  };
67 
68  template <typename T>
69  struct size {
70  using type = typename product_traits<T>::type;
72  };
73  template <>
74  struct size<Null> {
75  constexpr static int value = 0;
76  };
77 
78  template <typename T>
80  using type = typename T::element_type;
81  static auto getPointer(T const& iPtr) -> decltype(&*iPtr) { return &*iPtr; }
82  };
83 
84  template <typename T>
85  struct smart_pointer_traits<std::unique_ptr<const T>> {
86  using type = T;
87  static auto getPointer(std::unique_ptr<const T> const& iPtr) -> decltype(&*iPtr) { return &*iPtr; }
88  };
89 
90  template <typename T>
91  struct smart_pointer_traits<std::shared_ptr<const T>> {
92  using type = T;
93  static auto getPointer(std::shared_ptr<const T> const& iPtr) -> decltype(&*iPtr) { return &*iPtr; }
94  };
95 
96  template <typename T>
98  using type = T;
99  static T const* getPointer(std::optional<T> const& iPtr) {
100  if (iPtr.has_value()) {
101  return &*iPtr;
102  }
103  return nullptr;
104  }
105  };
106 
107  template <typename T, typename FindT>
108  struct find_index {
110  template <typename HeadT, typename TailT>
111  constexpr static int findIndexOf() {
112  if constexpr (not std::is_same_v<TailT, FindT>) {
114  return findIndexOf<typename container_type::head_type, typename container_type::tail_type>() + 1;
115  } else {
116  return 0;
117  }
118  }
119  constexpr static int value =
120  findIndexOf<typename container_type::head_type, typename container_type::tail_type>();
121  };
122  namespace test {
123  template <typename T>
124  const char* name(const T*);
125  }
126 
127  } // namespace produce
128 } // namespace edm::eventsetup
129 
130 #endif
typename product_traits< T >::type container_type
const char * name(const T *)
static T const * getPointer(std::optional< T > const &iPtr)
static auto getPointer(T const &iPtr) -> decltype(&*iPtr)
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
void moveFromTo(FromT &iFrom, ToT &iTo)
optional
Definition: Types.py:245
Definition: value.py:1
static auto getPointer(std::unique_ptr< const T > const &iPtr) -> decltype(&*iPtr)
static auto getPointer(std::shared_ptr< const T > const &iPtr) -> decltype(&*iPtr)
long double T
def move(src, dest)
Definition: eostools.py:511
typename product_traits< T >::type type