-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype_utils.hxx
99 lines (78 loc) · 1.78 KB
/
type_utils.hxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include <stddef.h>
template<template<class> class T, template<class> class U>
struct static_ttype_test
{
static const bool eq = false;
};
template<template<class> class T>
struct static_ttype_test<T, T>
{
static const bool eq = true;
};
template<class T, class U>
struct static_type_test
{
static const bool eq = false;
};
template<class T>
struct static_type_test<T, T>
{
static const bool eq = true;
};
// tests whether two types are equal
template<class T, class U>
constexpr bool static_type_eq()
{
return static_type_test<T, U>::eq;
}
template<template<class> class T, template<class> class U>
constexpr bool static_type_eq()
{
return static_ttype_test<T, U>::eq;
}
template<class ...Elems>
struct TList;
template<template<class> class ...Elems>
struct TTList;
#define MYTEMPL
#define TNAME TList
#include "tlist.hxx"
#undef TNAME
#undef MYTEMPL
#define MYTEMPL template<class>
#define TNAME TTList
#include "tlist.hxx"
#undef TNAME
#undef MYTEMPL
template<class T>
struct SizeofReducer {
constexpr auto operator()() {
return sizeof(T);
}
template<class NT>
constexpr auto feed() {
if constexpr (sizeof(NT) > sizeof(T))
return SizeofReducer<NT>{};
else
return SizeofReducer<T>{};
}
};
template<class T>
struct AlignofReducer {
constexpr auto operator()() {
return alignof(T);
}
template<class NT>
constexpr auto feed() {
if constexpr (alignof(NT) > alignof(T))
return AlignofReducer<NT>{};
else
return AlignofReducer<T>{};
}
};
template<template<class> class OldState, template<class> class NewState>
struct TTPair {
template<class T> using old_t = OldState<T>;
template<class T> using new_t = NewState<T>;
};