LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MetaUtils.h
Go to the documentation of this file.
1 
23 #ifndef LARCOREALG_COREUTILS_METAUTILS_H
24 #define LARCOREALG_COREUTILS_METAUTILS_H
25 
26 
27 // C/C++ standard libraries
28 #include <type_traits>
29 
30 
36 namespace util {
37 
38 
39  //--- BEGIN MetaprogrammingBase ----------------------------------------------
45 
47  namespace details {
48 
50  template <typename T>
52 
53  } // namespace details
54 
55 
56  //----------------------------------------------------------------------------
58  template <typename T>
59  struct self_type { using type = T; };
60 
62  template <typename T>
63  using self_t = typename self_type<T>::type;
64 
65 
66  //----------------------------------------------------------------------------
87  template <typename>
88  struct always_false_type: public std::false_type {};
89 
90 
91  //----------------------------------------------------------------------------
112  template <typename>
113  constexpr bool always_false_v = false;
114 
115 
138  template <typename>
139  struct always_true_type: public std::true_type {};
140 
141 
161  template <typename>
162  constexpr bool always_true_v = true;
163 
164 
165  // will be present in C++17 as std::bool_constant
167  template <bool Value>
168  using bool_constant = std::integral_constant<bool, Value>;
169 
170  // will be present in C++17 as std::negation
172  template <typename BoolTrait>
174 
177  template <typename A, typename B>
179 
180 
181  // @{
237  template <typename T>
238  void staticDumpClassName();
239 
240  template <typename T>
241  void staticDumpClassName(T) { staticDumpClassName<T>(); }
242  // @}
243 
244 
246  //--- END MetaprogrammingBase ------------------------------------------------
247 
248 
249 } // namespace util
250 
251 
252 //------------------------------------------------------------------------------
253 //--- Template implementation
254 //------------------------------------------------------------------------------
255 namespace util {
256 
257  //----------------------------------------------------------------------------
258  namespace details {
259 
261  template <typename T>
262  struct ClassNameStaticDumper {
263  static_assert(
265  "ClassNameStaticDumper<T>: look for T in the error message context"
266  );
267  }; // struct ClassNameStaticDumper
268 
269  } // namespace details
270 
271 
272  //----------------------------------------------------------------------------
273  template <typename T>
275 
276 
277  //----------------------------------------------------------------------------
278 
279 } // namespace util
280 
281 
282 //------------------------------------------------------------------------------
283 
284 #endif // LARCOREALG_COREUTILS_METAUTILS_H
285 
Implementation detail of staticDumpClassName().
Definition: MetaUtils.h:51
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
bool_constant<!BoolTrait::value > negation
Definition: MetaUtils.h:173
constexpr bool always_true_v
A template constant always true.
Definition: MetaUtils.h:162
std::integral_constant< bool, Value > bool_constant
Definition: MetaUtils.h:168
typename self_type< T >::type self_t
The very same type as in the template argument.
Definition: MetaUtils.h:63
A std::false_type with a template argument.
Definition: MetaUtils.h:88
Trait returning the very same type as in the template argument.
Definition: MetaUtils.h:59
constexpr bool always_false_v
A templated constant, always false.
Definition: MetaUtils.h:113
negation< std::is_same< A, B >> is_not_same
Definition: MetaUtils.h:178
A std::true_type with a template argument.
Definition: MetaUtils.h:139
void staticDumpClassName()
Helper to determine the type of a variable at compilation time.
Definition: MetaUtils.h:274