thepeg is hosted by Hepforge, IPPP Durham
ThePEG  2.1.5
TemplateTools.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // TemplateTools.h is a part of ThePEG - Toolkit for HEP Event Generation
4 // Copyright (C) 2006-2017 David Grellscheid, Leif Lonnblad
5 //
6 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
7 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
8 //
9 #ifndef Template_Tools_H
10 #define Template_Tools_H
11 
12 #include <type_traits>
13 
19 namespace ThePEG {
20 
22 template <int v>
23 struct Int2Type
24 {
25  enum { value = v };
26 };
27 
29 struct DummyType {};
30 
32 template <typename T, typename U>
33 struct BinaryOpTraits;
34 
37 template <>
38 struct BinaryOpTraits<double,double> {
40  typedef double MulT;
43  typedef double DivT;
44 };
45 
46 template <>
47 struct BinaryOpTraits<long double, long double> {
49  typedef long double MulT;
52  typedef long double DivT;
53 };
54 
55 template <>
56 struct BinaryOpTraits<int,int> {
58  typedef int MulT;
61  typedef int DivT;
62 };
63 
66 enum ImplSelector { Dimensioned, Standard };
68 
71 
74 
75 
77 template <typename T>
78 struct TypeTraits
79 {
81  enum { hasDimension = false };
83  typedef StandardT DimType;
85  // construction with extra U type is necessary to make
86  // enable_if work before concepts are supported properly
87  template <typename U = T>
88  static constexpr typename
89  std::enable_if< (std::is_arithmetic<U>::value &&
90  std::is_same<U, T>::value), U>::type
92  { return static_cast<U>(1); }
93 };
94 
95 }
96 
97 #endif
Conversion between integers and types.
Definition: TemplateTools.h:23
Dummy type for ambiguous function signatures.
Definition: TemplateTools.h:29
This is the main namespace within which all identifiers in ThePEG are declared.
Definition: FactoryBase.h:28
Int2Type< Dimensioned > DimensionT
Typedef for dimensioned types.
Definition: TemplateTools.h:70
ImplSelector
Selection mechanism for type-dependent implementations.
Definition: TemplateTools.h:67
StandardT DimType
Implementation selector.
Definition: TemplateTools.h:83
Type traits for built-in types.
Definition: TemplateTools.h:78
Int2Type< Standard > StandardT
Typedef for non-dimensioned types.
Definition: TemplateTools.h:73
BinaryOpTraits should be specialized with typdefs called MulT and DivT which gives the type resulting...
Definition: PhysicalQty.h:244
static constexpr std::enable_if<(std::is_arithmetic< U >::value &&std::is_same< U, T >::value), U >::type baseunit()
Base unit for arithmetic types.
Definition: TemplateTools.h:91