rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.2
TypeTraits.hh
1// -*- C++ -*-
2#ifndef RIVET_TypeTraits_HH
3#define RIVET_TypeTraits_HH
4
5#include <type_traits>
6#include <iterator>
7
8namespace Rivet {
9
10
18
20
21 struct RefType { };
22
23 struct PtrType { };
24
25 template <typename T>
26 struct TypeTraits;
27
28 template <typename U>
29 struct TypeTraits<const U&> {
30 using ArgType = RefType;
31 };
32
33 template <typename U>
34 struct TypeTraits<const U*> {
35 using ArgType = PtrType;
36 };
37
38 template<typename T>
39 struct TypeIdentity { using type = T; };
40
41
43 template<typename T>
44 using sign_if_integral = std::conditional_t<(std::is_integral_v<T> && !std::is_same_v<T,bool>),
45 std::make_signed<T>, TypeIdentity<T>>;
46 //
47 template<typename T>
48 using sign_if_integral_t = typename sign_if_integral<T>::type;
49
51 template<typename... Args>
52 using all_unsigned = std::conjunction<std::is_unsigned<Args>...>;
53
55 template<typename... Args>
56 using signed_if_mixed_t = std::conditional_t<all_unsigned<Args...>::value,
57 std::common_type_t<Args...>,
58 std::common_type_t<sign_if_integral_t<Args>...>>;
59
60
62 template <typename T, typename=void>
63 struct Derefable : std::false_type {};
64 //
65 template <typename T>
66 struct Derefable<T, std::void_t< decltype(*std::declval<T>())> > : std::true_type {};
67
68
72 template<typename T, typename = void>
73 struct Iterable : std::false_type { };
74 //
75 template<typename T>
76 struct Iterable<T, std::void_t<std::decay_t<decltype(std::begin(std::declval<const T&>()))>,
77 std::decay_t<decltype(std::end(std::declval<const T&>()))>>> : std::true_type { };
78
79 template<typename T>
80 inline constexpr bool is_iterable_v = Iterable<T>::value;
81
82 //template<typename... T>
83 //inline constexpr bool isIterable = std::conjunction<Iterable<T>...>::value;
84 template<typename T>
85 using isIterable = std::enable_if_t<Iterable<T>::value>;
86
87
88 // SFINAE struct to check for const_iterator concept
89 template<typename T, typename = void>
90 struct CIterable : std::false_type { };
91
92 template<typename T>
93 struct CIterable<T, std::void_t<decltype(std::declval<typename std::decay_t<T>::const_iterator>())>> : std::true_type { };
94
95 template<typename T>
96 inline constexpr bool is_citerable_v = CIterable<T>::value;
97
98 //template<typename... T>
99 //inline constexpr bool isCIterable = std::conjunction<CIterable<T>...>::value;
100 template<typename... Args>
101 using isCIterable = std::enable_if_t<(CIterable<Args>::value && ...)>;
102
103 // SFINAE struct to check for cstr
104 template<typename T>
105 struct isCString : std::false_type { };
106
107 template<>
108 struct isCString<char[]> : std::true_type { };
109
110 template<size_t N>
111 struct isCString<char[N]> : std::true_type { };
112
113 template <typename T>
114 inline constexpr bool is_cstring_v = isCString<T>::value;
115
116
118 template<typename T, typename = void>
119 struct hasBinning : std::false_type { };
120 //
121 template<typename T>
122 struct hasBinning<T, std::void_t<decltype(std::declval<T>().binning())>> : std::true_type { };
123
124
126 template<typename T, typename = void>
127 struct isFillable : std::false_type { };
128 //
129 template<typename T>
130 struct isFillable<T, std::void_t<decltype(typename T::FillType{})>> : std::true_type { };
131
132
133 // SFINAE struct to check if U can be used as an argument of T
134 template<typename T, typename U, typename = void>
135 struct isArgumentOf : std::false_type { };
136 //
137 template<typename T, typename U>
138 struct isArgumentOf<T, U, std::void_t<decltype(T(std::declval<U>()))>>
139 : std::true_type { };
140
142 template <typename T, typename... Us>
143 using allArgumentsOf = typename std::conjunction<isArgumentOf<T, Us>...>;
144
146 template <typename T, typename=void>
147 struct HasXYZ : std::false_type {};
148 template <typename T>
149 struct HasXYZ<T, std::void_t< decltype(std::declval<T>().x() + std::declval<T>().y() +
150 std::declval<T>().z())> > : std::true_type {};
151
152
154 template <typename T, typename=void>
155 struct HasXYZT : std::false_type {};
156 template <typename T>
157 struct HasXYZT<T, std::void_t< decltype(std::declval<T>().x() + std::declval<T>().y() +
158 std::declval<T>().z() + std::declval<T>().t())> > : std::true_type {};
159
160
162
163}
164
165#endif
Definition MC_CENT_PPB_Projections.hh:10
STL namespace.