LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
Dereference.h
Go to the documentation of this file.
1 
8 #ifndef LARDATA_UTILITIES_DEREFERENCE_H
9 #define LARDATA_UTILITIES_DEREFERENCE_H 1
10 
11 // C/C++ standard libraries
12 #include <type_traits>
13 
15 namespace lar {
17  namespace util {
19  namespace details {
20 
21 
23  template <typename T>
24  struct is_type: public std::true_type {};
25 
26 
28 
50  template <typename T, typename Enable = void>
51  struct has_dereference_class: public std::false_type {};
52 
53  template <typename T>
55  T,
56  typename std::enable_if<is_type<decltype(*(T()))>::value, void>::type
57  >:
58  public std::true_type
59  {};
61 
62 
64 
99  template <typename T, bool CanDereference>
101  // using type = typename std::add_lvalue_reference<T>::type;
102  using type = T;
103  }; // dereferenced_type <>
104 
105  template <typename T>
106  struct dereferenced_type<T, true> {
107  using type = decltype(*T());
108  }; // dereferenced_type<T, true>
110 
111 
112 
114 
131  template <typename T, bool CanDereference>
133  using argument_type = T;
134  using reference_type = typename std::add_lvalue_reference
136 
137  reference_type operator() (argument_type& ref) const { return ref; }
138  }; // dereference_class<T, bool>
139 
140 
141  template <typename T>
142  struct dereference_class<T, true> {
143  using argument_type = T;
144  using reference_type = typename std::add_lvalue_reference
146 
147  reference_type operator() (argument_type& ref) const { return *ref; }
148  }; // dereference_class<T, true>
150 
151 
153 
170  template <typename T, bool CanDereference>
172  using argument_type = T;
173  using pointer_type = typename std::add_pointer
175 
176  pointer_type operator() (argument_type& ref) const { return &ref; }
177  }; // make_pointer_class<T, bool>
178 
179 
180  template <typename T>
181  struct make_pointer_class<T, true> {
182  using argument_type = T;
183  using pointer_type = typename std::add_pointer
185 
186  pointer_type operator() (argument_type& ref) const { return &*ref; }
187  }; // make_pointer_class<T, true>
189 
190  } // namespace details
191 
192 
215  template <typename T>
216  struct dereferenced_type: public
217  details::dereferenced_type<T, details::has_dereference_class<T>::value>
218  {};
219 
220 
250  template <typename T>
251  inline
253  <T, details::has_dereference_class<T>::value>::reference_type
255  {
258  }
259 
289  template <typename T>
290  inline
294  {
297  }
298 
299  } // namespace util
300 
301 } // namespace lar
302 
303 #endif // LARDATA_UTILITIES_DEREFERENCE_H
Functor returning the dereferenced value of the argument.
Definition: Dereference.h:132
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
details::make_pointer_class< T, details::has_dereference_class< T >::value >::pointer_type make_pointer(T &v)
Returns a pointer to the value of argument, or the argument itself.
Definition: Dereference.h:293
typename std::add_lvalue_reference< typename dereferenced_type< T, CanDereference >::type >::type reference_type
Definition: Dereference.h:135
typename std::add_lvalue_reference< typename dereferenced_type< T, true >::type >::type reference_type
Definition: Dereference.h:145
STL namespace.
Functor returning the pointer to a value in the argument.
Definition: Dereference.h:171
typename std::add_pointer< typename dereferenced_type< T, CanDereference >::type >::type pointer_type
Definition: Dereference.h:174
typename std::add_pointer< typename dereferenced_type< T, true >::type >::type pointer_type
Definition: Dereference.h:184
details::dereference_class< T, details::has_dereference_class< T >::value >::reference_type dereference(T &v)
Returns the value pointed by the argument, or the argument itself.
Definition: Dereference.h:254
Class defining the dereferenced type of the specified type.
Definition: Dereference.h:216
LArSoft-specific namespace.
Class holding the type dereferenced from an object of type T.
Definition: Dereference.h:100
Class compiling only if type T exists (then, it&#39;s std::true_type)
Definition: Dereference.h:24
Class defining whether the specified type can be dereferenced.
Definition: Dereference.h:51