rivet is hosted by Hepforge, IPPP Durham
Rivet 4.0.0
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
39
41 template <typename T, typename=void>
42 struct Derefable : std::false_type {};
43 //
44 template <typename T>
45 struct Derefable<T, std::void_t< decltype(*std::declval<T>())> > : std::true_type {};
46
47
51 template<typename T, typename = void>
52 struct Iterable : std::false_type { };
53 //
54 template<typename T>
55 struct Iterable<T, std::void_t<std::decay_t<decltype(std::begin(std::declval<const T&>()))>,
56 std::decay_t<decltype(std::end(std::declval<const T&>()))>>> : std::true_type { };
57
58 template<typename T>
59 inline constexpr bool is_iterable_v = Iterable<T>::value;
60
61 //template<typename... T>
62 //inline constexpr bool isIterable = std::conjunction<Iterable<T>...>::value;
63 template<typename T>
64 using isIterable = std::enable_if_t<Iterable<T>::value>;
65
66
67 // SFINAE struct to check for const_iterator concept
68 template<typename T, typename = void>
69 struct CIterable : std::false_type { };
70
71 template<typename T>
72 struct CIterable<T, std::void_t<decltype(std::declval<typename std::decay_t<T>::const_iterator>())>> : std::true_type { };
73
74 template<typename T>
75 inline constexpr bool is_citerable_v = CIterable<T>::value;
76
77 //template<typename... T>
78 //inline constexpr bool isCIterable = std::conjunction<CIterable<T>...>::value;
79 template<typename... Args>
80 using isCIterable = std::enable_if_t<(CIterable<Args>::value && ...)>;
81
82 // SFINAE struct to check for cstr
83 template<typename T>
84 struct isCString : std::false_type { };
85
86 template<>
87 struct isCString<char[]> : std::true_type { };
88
89 template<size_t N>
90 struct isCString<char[N]> : std::true_type { };
91
92 template <typename T>
93 inline constexpr bool is_cstring_v = isCString<T>::value;
94
95
97 template<typename T, typename = void>
98 struct hasBinning : std::false_type { };
99 //
100 template<typename T>
101 struct hasBinning<T, std::void_t<decltype(std::declval<T>().binning())>> : std::true_type { };
102
103
105 template<typename T, typename = void>
106 struct isFillable : std::false_type { };
107 //
108 template<typename T>
109 struct isFillable<T, std::void_t<decltype(typename T::FillType{})>> : std::true_type { };
110
111
112 // SFINAE struct to check if U can be used as an argument of T
113 template<typename T, typename U, typename = void>
114 struct isArgumentOf : std::false_type { };
115 //
116 template<typename T, typename U>
117 struct isArgumentOf<T, U, std::void_t<decltype(T(std::declval<U>()))>>
118 : std::true_type { };
119
121 template <typename T, typename... Us>
122 using allArgumentsOf = typename std::conjunction<isArgumentOf<T, Us>...>;
123
125 template <typename T, typename=void>
126 struct HasXYZ : std::false_type {};
127 template <typename T>
128 struct HasXYZ<T, std::void_t< decltype(std::declval<T>().x() + std::declval<T>().y() +
129 std::declval<T>().z())> > : std::true_type {};
130
131
133 template <typename T, typename=void>
134 struct HasXYZT : std::false_type {};
135 template <typename T>
136 struct HasXYZT<T, std::void_t< decltype(std::declval<T>().x() + std::declval<T>().y() +
137 std::declval<T>().z() + std::declval<T>().t())> > : std::true_type {};
138
139
141
142}
143
144#endif
Definition MC_CENT_PPB_Projections.hh:10
STL namespace.