CMS 3D CMS Logo

WrapperDetail.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_WrapperDetail_h
2 #define DataFormats_Common_WrapperDetail_h
3 
4 /*----------------------------------------------------------------------
5 
6 WrapperDetail: Metafunction support for compile-time selection of code.
7 
8 ----------------------------------------------------------------------*/
9 
10 #include <memory>
11 #include <typeinfo>
12 #include <type_traits>
13 #include <vector>
14 
15 namespace edm {
16 
17  //Need to specialize the case of std::vector<edm::Ptr<T>>
18  template <typename T>
19  class Ptr;
20 
21  namespace detail {
22  using no_tag = std::false_type; // type indicating FALSE
23  using yes_tag = std::true_type; // type indicating TRUE
24 
25  // valueTypeInfo_() will return typeid(T::value_type) if T::value_type is declared and typeid(void) otherwise.
26  // Definitions for the following struct and function templates are not needed; we only require the declarations.
27  template <typename T>
28  static yes_tag has_value_type(typename T::value_type*);
29  template <typename T>
30  static no_tag has_value_type(...);
31 
32  template <typename T>
34  static constexpr bool value = std::is_same<decltype(has_value_type<T>(nullptr)), yes_tag>::value;
35  };
37  struct getValueType;
38  template <typename T>
39  struct getValueType<T, true> {
40  std::type_info const& operator()() { return typeid(typename T::value_type); }
41  };
42  template <typename T>
43  struct getValueType<T, false> {
44  std::type_info const& operator()() { return typeid(void); }
45  };
46 
47  // memberTypeInfo_() will return typeid(T::member_type) if T::member_type is declared and typeid(void) otherwise.
48  // Definitions for the following struct and function templates are not needed; we only require the declarations.
49  template <typename T>
50  static yes_tag has_member_type(typename T::member_type*);
51  template <typename T>
52  static no_tag has_member_type(...);
53 
54  template <typename T>
56  static constexpr bool value = std::is_same<decltype(has_member_type<T>(nullptr)), yes_tag>::value;
57  };
59  struct getMemberType;
60  template <typename T>
61  struct getMemberType<T, true> {
62  std::type_info const& operator()() { return typeid(typename T::member_type); }
63  };
64  template <typename T>
65  struct getMemberType<T, false> {
66  std::type_info const& operator()() { return typeid(void); }
67  };
68 
69  template <typename T>
70  struct has_typedef_member_type<std::vector<edm::Ptr<T> > > {
71  static constexpr bool value = true;
72  };
73 
74  template <typename T>
75  struct getMemberType<std::vector<edm::Ptr<T> >, true> {
76  std::type_info const& operator()() { return typeid(T); }
77  };
78 
79  template <typename T, typename Deleter>
80  struct has_typedef_member_type<std::vector<std::unique_ptr<T, Deleter> > > {
81  static constexpr bool value = true;
82  };
83 
84  template <typename T, typename Deleter>
85  struct getMemberType<std::vector<std::unique_ptr<T, Deleter> >, true> {
86  std::type_info const& operator()() { return typeid(T); }
87  };
88 
89  } // namespace detail
90 } // namespace edm
91 #endif
std::false_type no_tag
Definition: WrapperDetail.h:22
std::true_type yes_tag
Definition: WrapperDetail.h:23
std::type_info const & operator()()
Definition: WrapperDetail.h:66
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
std::type_info const & operator()()
Definition: WrapperDetail.h:44
std::type_info const & operator()()
Definition: WrapperDetail.h:62
Definition: value.py:1
static yes_tag has_member_type(typename T::member_type *)
HLT enums.
std::type_info const & operator()()
Definition: WrapperDetail.h:40
static yes_tag has_value_type(typename T::value_type *)
long double T