traits_t.cc
Go to the documentation of this file.
1 #include "cetlib_except/demangle.h"
3 #include "fhiclcpp/type_traits.h"
4 
5 #include <cstdint>
6 #include <iostream>
7 #include <string>
8 #include <type_traits>
9 #include <typeinfo>
10 
11 template <typename T>
13  : public std::integral_constant<bool,
14  tt::is_int<T>::value ==
15  tt_old::is_int<T>::value> {};
16 
17 template <typename T>
19  : public std::integral_constant<bool,
20  tt::is_uint<T>::value ==
21  tt_old::is_uint<T>::value> {};
22 
23 template <typename T>
25  : public std::integral_constant<bool,
26  tt::is_numeric<T>::value ==
27  tt_old::is_numeric<T>::value> {};
28 
29 template <typename T>
30 void
31 assert_cmp(bool exp, std::string const op)
32 {
33  if (!exp) {
34  throw std::string("Failed ") + op + " for type " +
35  cet::demangle_symbol(typeid(T).name()) + ".";
36  }
37 }
38 
39 int
40 main() try {
41  // Walter's old templates did not specialize for char, therefore
42  // is_int<char> and is_uint<char> were both false.
43  char x = -1;
44  signed char y = -1;
45  if (int(x) == int(y)) { // char == signed char.
46  assert_cmp<char>(tt::is_int<char>::value, "is_int");
47  assert_cmp<char const>(tt::is_int<char const>::value, "is_int");
48  assert_cmp<char>(!tt::is_uint<char>::value, "is_uint");
49  assert_cmp<char const>(!tt::is_uint<char const>::value, "is_uint");
50  } else { // char == unsigned char.
51  assert_cmp<char>(!tt::is_int<char>::value, "is_int");
52  assert_cmp<char const>(!tt::is_int<char const>::value, "is_int");
53  assert_cmp<char>(tt::is_uint<char>::value, "is_uint");
54  assert_cmp<char const>(tt::is_uint<char const>::value, "is_uint");
55  }
56  assert_cmp<char>(tt::is_numeric<char>::value, "is_numeric");
57  assert_cmp<char const>(tt::is_numeric<char const>::value, "is_numeric");
58  // These types should all return the same value for new and old templates.
59  assert_cmp<signed char>(compare_is_int<signed char>::value, "compare is_int");
60  assert_cmp<signed char>(compare_is_uint<signed char>::value,
61  "compare is_uint");
62  assert_cmp<signed char>(compare_is_numeric<signed char>::value,
63  "compare is_numeric");
64  assert_cmp<signed char const>(compare_is_int<signed char const>::value,
65  "compare is_int");
66  assert_cmp<signed char const>(compare_is_uint<signed char const>::value,
67  "compare is_uint");
68  assert_cmp<signed char const>(compare_is_numeric<signed char const>::value,
69  "compare is_numeric");
70  assert_cmp<unsigned char>(compare_is_int<unsigned char>::value,
71  "compare is_int");
72  assert_cmp<unsigned char>(compare_is_uint<unsigned char>::value,
73  "compare is_uint");
74  assert_cmp<unsigned char>(compare_is_numeric<unsigned char>::value,
75  "compare is_numeric");
76  assert_cmp<unsigned char const>(compare_is_int<unsigned char const>::value,
77  "compare is_int");
78  assert_cmp<unsigned char const>(compare_is_uint<unsigned char const>::value,
79  "compare is_uint");
80  assert_cmp<unsigned char const>(
82  assert_cmp<short>(compare_is_int<short>::value, "compare is_int");
83  assert_cmp<short>(compare_is_uint<short>::value, "compare is_uint");
84  assert_cmp<short>(compare_is_numeric<short>::value, "compare is_numeric");
85  assert_cmp<short const>(compare_is_int<short const>::value, "compare is_int");
86  assert_cmp<short const>(compare_is_uint<short const>::value,
87  "compare is_uint");
88  assert_cmp<short const>(compare_is_numeric<short const>::value,
89  "compare is_numeric");
90  assert_cmp<unsigned short>(compare_is_int<unsigned short>::value,
91  "compare is_int");
92  assert_cmp<unsigned short>(compare_is_uint<unsigned short>::value,
93  "compare is_uint");
94  assert_cmp<unsigned short>(compare_is_numeric<unsigned short>::value,
95  "compare is_numeric");
96  assert_cmp<unsigned short const>(compare_is_int<unsigned short const>::value,
97  "compare is_int");
98  assert_cmp<unsigned short const>(compare_is_uint<unsigned short const>::value,
99  "compare is_uint");
100  assert_cmp<unsigned short const>(
102  assert_cmp<int>(compare_is_int<int>::value, "compare is_int");
103  assert_cmp<int>(compare_is_uint<int>::value, "compare is_uint");
104  assert_cmp<int>(compare_is_numeric<int>::value, "compare is_numeric");
105  assert_cmp<int const>(compare_is_int<int const>::value, "compare is_int");
106  assert_cmp<int const>(compare_is_uint<int const>::value, "compare is_uint");
107  assert_cmp<int const>(compare_is_numeric<int const>::value,
108  "compare is_numeric");
109  assert_cmp<unsigned int>(compare_is_int<unsigned int>::value,
110  "compare is_int");
111  assert_cmp<unsigned int>(compare_is_uint<unsigned int>::value,
112  "compare is_uint");
113  assert_cmp<unsigned int>(compare_is_numeric<unsigned int>::value,
114  "compare is_numeric");
115  assert_cmp<unsigned int const>(compare_is_int<unsigned int const>::value,
116  "compare is_int");
117  assert_cmp<unsigned int const>(compare_is_uint<unsigned int const>::value,
118  "compare is_uint");
119  assert_cmp<unsigned int const>(compare_is_numeric<unsigned int const>::value,
120  "compare is_numeric");
121  assert_cmp<long>(compare_is_int<long>::value, "compare is_int");
122  assert_cmp<long>(compare_is_uint<long>::value, "compare is_uint");
123  assert_cmp<long>(compare_is_numeric<long>::value, "compare is_numeric");
124  assert_cmp<long const>(compare_is_int<long const>::value, "compare is_int");
125  assert_cmp<long const>(compare_is_uint<long const>::value, "compare is_uint");
126  assert_cmp<long const>(compare_is_numeric<long const>::value,
127  "compare is_numeric");
128  assert_cmp<unsigned long>(compare_is_int<unsigned long>::value,
129  "compare is_int");
130  assert_cmp<unsigned long>(compare_is_uint<unsigned long>::value,
131  "compare is_uint");
132  assert_cmp<unsigned long>(compare_is_numeric<unsigned long>::value,
133  "compare is_numeric");
134  assert_cmp<unsigned long const>(compare_is_int<unsigned long const>::value,
135  "compare is_int");
136  assert_cmp<unsigned long const>(compare_is_uint<unsigned long const>::value,
137  "compare is_uint");
138  assert_cmp<unsigned long const>(
139  compare_is_numeric<unsigned long const>::value, "compare is_numeric");
140  // Walter's old templates did not specialize for long long or unsigned
141  // long long, therefore is_int and is_uint were both false.
142  assert_cmp<long long>(tt::is_int<long long>::value, "is_int");
143  assert_cmp<long long>(!tt::is_uint<long long>::value, "is_uint");
144  assert_cmp<long long>(tt::is_numeric<long long>::value, "is_numeric");
145  assert_cmp<long long const>(tt::is_int<long long const>::value, "is_int");
146  assert_cmp<long long const>(!tt::is_uint<long long const>::value, "is_uint");
147  assert_cmp<long long const>(tt::is_numeric<long long const>::value,
148  "is_numeric");
149  assert_cmp<unsigned long long>(!tt::is_int<unsigned long long>::value,
150  "is_int");
151  assert_cmp<unsigned long long>(tt::is_uint<unsigned long long>::value,
152  "is_uint");
153  assert_cmp<unsigned long long>(tt::is_numeric<unsigned long long>::value,
154  "is_numeric");
155  assert_cmp<unsigned long long const>(
157  assert_cmp<unsigned long long const>(
159  assert_cmp<unsigned long long const>(
161  // Walter's old templates did not specialize for int64_t or uint64_t,
162  // meaning that is_int and is_uint were platform-dependent (hinging on
163  // whether int64_t was typedef'd to long or to long long).
164  assert_cmp<int64_t>(tt::is_int<int64_t>::value, "is_int");
165  assert_cmp<int64_t>(!tt::is_uint<int64_t>::value, "is_uint");
166  assert_cmp<int64_t>(tt::is_numeric<int64_t>::value, "is_numeric");
167  assert_cmp<int64_t const>(tt::is_int<int64_t const>::value, "is_int");
168  assert_cmp<int64_t const>(!tt::is_uint<int64_t const>::value, "is_uint");
169  assert_cmp<int64_t const>(tt::is_numeric<int64_t const>::value, "is_numeric");
170  assert_cmp<uint64_t>(!tt::is_int<uint64_t>::value, "is_int");
171  assert_cmp<uint64_t>(tt::is_uint<uint64_t>::value, "is_uint");
172  assert_cmp<uint64_t>(tt::is_numeric<uint64_t>::value, "is_numeric");
173  assert_cmp<uint64_t const>(!tt::is_int<uint64_t const>::value, "is_int");
174  assert_cmp<uint64_t const>(tt::is_uint<uint64_t const>::value, "is_uint");
175  assert_cmp<uint64_t const>(tt::is_numeric<uint64_t const>::value,
176  "is_numeric");
177  assert_cmp<float>(compare_is_int<float>::value, "compare is_int");
178  assert_cmp<float>(compare_is_uint<float>::value, "compare is_uint");
179  assert_cmp<float>(compare_is_numeric<float>::value, "compare is_numeric");
180  assert_cmp<float const>(compare_is_int<float const>::value, "compare is_int");
181  assert_cmp<float const>(compare_is_uint<float const>::value,
182  "compare is_uint");
183  assert_cmp<float const>(compare_is_numeric<float const>::value,
184  "compare is_numeric");
185  assert_cmp<double>(compare_is_int<double>::value, "compare is_int");
186  assert_cmp<double>(compare_is_uint<double>::value, "compare is_uint");
187  assert_cmp<double>(compare_is_numeric<double>::value, "compare is_numeric");
188  assert_cmp<double const>(compare_is_int<double const>::value,
189  "compare is_int");
190  assert_cmp<double const>(compare_is_uint<double const>::value,
191  "compare is_uint");
192  assert_cmp<double const>(compare_is_numeric<double const>::value,
193  "compare is_numeric");
194  assert_cmp<long double>(compare_is_int<long double>::value, "compare is_int");
195  assert_cmp<long double>(compare_is_uint<long double>::value,
196  "compare is_uint");
197  assert_cmp<long double>(compare_is_numeric<long double>::value,
198  "compare is_numeric");
199  assert_cmp<long double const>(compare_is_int<long double const>::value,
200  "compare is_int");
201  assert_cmp<long double const>(compare_is_uint<long double const>::value,
202  "compare is_uint");
203  assert_cmp<long double const>(compare_is_numeric<long double const>::value,
204  "compare is_numeric");
205 }
206 catch (std::string const& msg) {
207  std::cerr << msg << "\n";
208  throw;
209 }
static QCString name
Definition: declinfo.cpp:673
std::is_unsigned< T > is_uint
Definition: type_traits.h:79
std::is_arithmetic< T > is_numeric
Definition: type_traits.h:76
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
int main()
Definition: traits_t.cc:40
void assert_cmp(bool exp, std::string const op)
Definition: traits_t.cc:31
list x
Definition: train.py:276