1#ifndef CLICK_TYPE_TRAITS_HH
2#define CLICK_TYPE_TRAITS_HH
21template <
typename T, T V>
25 static constexpr T value = V;
43template <
bool B,
typename T,
typename F>
struct conditional {};
45template <
typename T,
typename F>
50template <
typename T,
typename F>
61#if HAVE___IS_TRIVIALLY_COPYABLE
63#elif HAVE___HAS_TRIVIAL_COPY
92#if HAVE_CXX_RVALUE_REFERENCES
108#if HAVE_CXX_RVALUE_REFERENCES
113inline typename remove_reference<T>::type&& click_move(T&& x) {
114 return static_cast<typename remove_reference<T>::type&&
>(x);
118template <
typename T>
struct remove_cv {
121template <
typename T>
struct remove_cv<const T> {
124template <
typename T>
struct remove_cv<volatile T> {
127template <
typename T>
struct remove_cv<const volatile T> {
131template <
typename T,
typename U>
struct same_type :
public false_type {};
132template <
typename T>
struct same_type<T, T> :
public true_type {};
134template <
typename T,
typename U>
struct types_compatible
135 :
public same_type<typename remove_cv<T>::type, typename remove_cv<U>::type> {};
145template <
typename T,
bool use_reference = (!is_reference<T>::value
146 && (!has_trivial_copy<T>::value
147 || sizeof(T) >
sizeof(
void *)))>
152 typedef const T &type;
153#if HAVE_CXX_RVALUE_REFERENCES
154 typedef void enable_rvalue_reference;
169} CLICK_SIZE_PACKED_ATTRIBUTE;
173#if HAVE_INT64_TYPES && (!HAVE_LONG_LONG || SIZEOF_LONG_LONG < 8)
174typedef int64_t click_intmax_t;
175typedef uint64_t click_uintmax_t;
176# define SIZEOF_CLICK_INTMAX_T 8
177# define CLICK_ERRHdMAX "^64d"
178# define CLICK_ERRHuMAX "^64u"
179# define CLICK_ERRHoMAX "^64o"
180# define CLICK_ERRHxMAX "^64x"
181# define CLICK_ERRHXMAX "^64X"
183typedef long long click_intmax_t;
184typedef unsigned long long click_uintmax_t;
185# define SIZEOF_CLICK_INTMAX_T SIZEOF_LONG_LONG
186# define CLICK_ERRHdMAX "lld"
187# define CLICK_ERRHuMAX "llu"
188# define CLICK_ERRHoMAX "llo"
189# define CLICK_ERRHxMAX "llx"
190# define CLICK_ERRHXMAX "llX"
192typedef long click_intmax_t;
193typedef unsigned long click_uintmax_t;
194# define SIZEOF_CLICK_INTMAX_T SIZEOF_LONG
195# define CLICK_ERRHdMAX "ld"
196# define CLICK_ERRHuMAX "lu"
197# define CLICK_ERRHoMAX "lo"
198# define CLICK_ERRHxMAX "lx"
199# define CLICK_ERRHXMAX "lX"
202typedef click_intmax_t click_int_large_t;
203typedef click_uintmax_t click_uint_large_t;
204#define SIZEOF_CLICK_INT_LARGE_T SIZEOF_CLICK_INTMAX_T
205#define CLICK_ERRHdLARGE CLICK_ERRHdMAX
206#define CLICK_ERRHuLARGE CLICK_ERRHuMAX
207#define CLICK_ERRHoLARGE CLICK_ERRHoMAX
208#define CLICK_ERRHxLARGE CLICK_ERRHxMAX
209#define CLICK_ERRHXLARGE CLICK_ERRHXMAX
245 static constexpr bool is_numeric =
false;
246 static constexpr bool is_integral =
false;
253 static constexpr bool is_numeric =
true;
254 static constexpr bool is_integral =
true;
255 static constexpr unsigned char const_min = 0;
256 static constexpr unsigned char const_max = ~const_min;
257 static constexpr bool is_signed =
false;
258 typedef signed char signed_type;
259 typedef unsigned char unsigned_type;
260 typedef unsigned char type;
261 typedef click_uintmax_t max_type;
262 static bool negative(type) {
return false; }
267 static constexpr bool is_numeric =
true;
268 static constexpr bool is_integral =
true;
269 static constexpr signed char const_min = -128;
270 static constexpr signed char const_max = 127;
271 static constexpr bool is_signed =
true;
272 typedef signed char signed_type;
273 typedef unsigned char unsigned_type;
274 typedef signed char type;
275 typedef click_intmax_t max_type;
276 static bool negative(type x) {
return x < 0; }
282 static constexpr char const_min = 0;
283 static constexpr char const_max = ~const_min;
285 static bool negative(type) {
return false; }
290 static constexpr char const_min = -128;
291 static constexpr char const_max = 127;
293 static bool negative(type x) {
return x < 0; }
299 static constexpr bool is_numeric =
true;
300 static constexpr bool is_integral =
true;
301 static constexpr unsigned short const_min = 0;
302 static constexpr unsigned short const_max = ~const_min;
303 static constexpr bool is_signed =
false;
304 typedef short signed_type;
305 typedef unsigned short unsigned_type;
306 typedef unsigned short type;
307 typedef click_uintmax_t max_type;
308 static bool negative(type) {
return false; }
313 static constexpr bool is_numeric =
true;
314 static constexpr bool is_integral =
true;
315 static constexpr short const_min = -32768;
316 static constexpr short const_max = 32767;
317 static constexpr bool is_signed =
true;
318 typedef short signed_type;
319 typedef unsigned short unsigned_type;
321 typedef click_intmax_t max_type;
322 static bool negative(type x) {
return x < 0; }
327 static constexpr bool is_numeric =
true;
328 static constexpr bool is_integral =
true;
329 static constexpr unsigned int const_min = 0;
330 static constexpr unsigned int const_max = ~const_min;
331 static constexpr bool is_signed =
false;
332 typedef int signed_type;
333 typedef unsigned int unsigned_type;
334 typedef unsigned int type;
335 typedef click_uintmax_t max_type;
336 static bool negative(type) {
return false; }
341 static constexpr bool is_numeric =
true;
342 static constexpr bool is_integral =
true;
343 static constexpr int const_min = 1 << (8*SIZEOF_INT - 1);
344 static constexpr int const_max = (unsigned) const_min - 1;
345 static constexpr bool is_signed =
true;
346 typedef int signed_type;
347 typedef unsigned int unsigned_type;
349 typedef click_intmax_t max_type;
350 static bool negative(type x) {
return x < 0; }
355 static constexpr bool is_numeric =
true;
356 static constexpr bool is_integral =
true;
357 static constexpr unsigned long const_min = 0;
358 static constexpr unsigned long const_max = ~const_min;
359 static constexpr bool is_signed =
false;
360 typedef long signed_type;
361 typedef unsigned long unsigned_type;
362 typedef unsigned long type;
363 typedef click_uintmax_t max_type;
364 static bool negative(type) {
return false; }
369 static constexpr bool is_numeric =
true;
370 static constexpr bool is_integral =
true;
371 static constexpr long const_min = (long) 1 << (8*SIZEOF_LONG - 1);
372 static constexpr long const_max = (
unsigned long) const_min - 1;
373 static constexpr bool is_signed =
true;
374 typedef long signed_type;
375 typedef unsigned long unsigned_type;
377 typedef click_intmax_t max_type;
378 static bool negative(type x) {
return x < 0; }
384 static constexpr bool is_numeric =
true;
385 static constexpr bool is_integral =
true;
386 static constexpr unsigned long long const_min = 0;
387 static constexpr unsigned long long const_max = ~const_min;
388 static constexpr bool is_signed =
false;
389 typedef long long signed_type;
390 typedef unsigned long long unsigned_type;
391 typedef unsigned long long type;
392 typedef click_uintmax_t max_type;
393 static bool negative(type) {
return false; }
398 static constexpr bool is_numeric =
true;
399 static constexpr bool is_integral =
true;
400 static constexpr long long const_min = (
long long) 1 << (8*SIZEOF_LONG_LONG - 1);
401 static constexpr long long const_max = (
unsigned long long) const_min - 1;
402 static constexpr bool is_signed =
true;
403 typedef long long signed_type;
404 typedef unsigned long long unsigned_type;
405 typedef long long type;
406 typedef click_intmax_t max_type;
407 static bool negative(type x) {
return x < 0; }
411#if HAVE_INT64_TYPES && !HAVE_INT64_IS_LONG && !HAVE_INT64_IS_LONG_LONG
414 static constexpr bool is_numeric =
true;
415 static constexpr bool is_integral =
true;
416 static constexpr uint64_t const_min = 0;
417 static constexpr uint64_t const_max = ~const_min;
418 static constexpr bool is_signed =
false;
419 typedef int64_t signed_type;
420 typedef uint64_t unsigned_type;
421 typedef uint64_t type;
422 typedef click_uintmax_t max_type;
423 static bool negative(type) {
return false; }
428 static constexpr bool is_numeric =
true;
429 static constexpr bool is_integral =
true;
430 static constexpr int64_t const_min = (int64_t) 1 << 63;
431 static constexpr int64_t const_max = (uint64_t) const_min - 1;
432 static constexpr bool is_signed =
true;
433 typedef int64_t signed_type;
434 typedef uint64_t unsigned_type;
435 typedef int64_t type;
436 typedef click_intmax_t max_type;
437 static bool negative(type x) {
return x < 0; }
468template <
typename T,
typename Thalf>
469struct make_fast_half_integer {
471 typedef Thalf half_type;
472 static constexpr int half_bits = int(
sizeof(type) * 4);
473 static constexpr type half_value = type(1) << half_bits;
474 static half_type low(type x) {
475 return x & (half_value - 1);
477 static half_type high(type x) {
478 return x >> (
sizeof(type) * 4);
487#if SIZEOF_LONG >= 8 && SIZEOF_LONG <= 2 * SIZEOF_INT
488template <>
struct fast_half_integer<unsigned long> :
public make_fast_half_integer<unsigned long, unsigned int> {};
491#if HAVE_LONG_LONG && SIZEOF_LONG_LONG <= 2 * SIZEOF_INT
492template <>
struct fast_half_integer<unsigned long long> :
public make_fast_half_integer<unsigned long long, unsigned int> {};
495#if HAVE_INT64_TYPES && !HAVE_INT64_IS_LONG_LONG && !HAVE_INT64_IS_LONG && SIZEOF_INT >= 4
496template <>
struct fast_half_integer<uint64_t> :
public make_fast_half_integer<uint64_t, unsigned int> {};
500template <
int n,
typename Limb,
typename V>
501struct extract_integer_helper {
502 static void extract(
const Limb *x, V &value) {
503 extract_integer_helper<n - 1, Limb, V>::extract(x + 1, value);
504 value = (value << (
sizeof(Limb) * 8)) | *x;
508template <
typename Limb,
typename V>
509struct extract_integer_helper<1, Limb, V> {
510 static void extract(
const Limb *x, V &value) {
516template <
typename Limb,
typename V>
518 extract_integer_helper<
519 int((
sizeof(V) +
sizeof(Limb) - 1) /
sizeof(Limb)), Limb, V
520 >::extract(x, value);
An IPv4 address.
Definition ipaddress.hh:16
Type wrapper for the constant false.
Type wrapper for the constant true.
Template defining a fixed-size character array.
Definition type_traits.hh:167
Conditional type transformation.
Definition type_traits.hh:43
Template defining a fast argument type for objects of type T.
Definition type_traits.hh:148
Type transformation for big integers.
Definition type_traits.hh:485
Template determining whether T may be copied by memcpy.
Definition type_traits.hh:66
Numeric traits template.
Definition type_traits.hh:244
Type wrapper for an integral constant V.
Definition type_traits.hh:22
Template determining whether T is a reference type.
Definition type_traits.hh:90
Signed integer type transformation.
Definition type_traits.hh:450
Unsigned integer type transformation.
Definition type_traits.hh:462
Template removing any reference layer from T.
Definition type_traits.hh:102
void extract_integer(const Limb *x, V &value)
Extract an integral type from a multi-limb integer.
Definition type_traits.hh:517