-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
84 lines (63 loc) · 2.6 KB
/
Copy pathtest.cpp
File metadata and controls
84 lines (63 loc) · 2.6 KB
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
#include <iomanip>
#include <iostream>
#include <type_traits>
#include "type_classifiers.h"
using typing::Type;
using SignedIntType = decltype(Type<int>() || Type<int8_t>() || Type<int16_t>() || Type<int32_t>() || Type<int64_t>());
template <typename T>
struct Int {
static_assert(
Type<T>() == SignedIntType(),
"Int template argument must be a signed `int` type"
);
};
template <typename T1, typename T2>
struct IntPair {
static_assert(
(Type<T1>() && Type<T2>()) == (Type<int>() || Type<int8_t>() || Type<int16_t>() || Type<int32_t>() || Type<int64_t>()),
"IntPair template arguments must be signed `int` types"
);
};
template <typename T1, typename T2>
typename std::enable_if<((Type<T1>() && Type<T2>()) == SignedIntType())>::type
f() {
std::cout << "f()\n";
}
template <typename T>
typename std::enable_if<(Type<T>() == !Type<int>())>::type
g() {
std::cout << "g()\n";
}
int main() {
static_assert(Type<int>() == (Type<int>() || Type<int8_t>()), "Ruh Roh");
static_assert((Type<int>() || Type<int8_t>()) == (Type<int>() || Type<int8_t>()), "Ruh Roh");
static_assert(Type<int>() != (Type<unsigned>() || Type<uint8_t>()), "Ruh Roh");
static_assert(Type<int>() == !(Type<unsigned>() || Type<uint8_t>()), "Ruh Roh");
static_assert(Type<int>() == (!Type<unsigned>() && !Type<uint8_t>()), "Ruh Roh");
static_assert(!(Type<int>() != Type<int>()), "Ruh Roh");
static_assert(!(Type<int>() == !Type<int>()), "Ruh Roh");
static_assert((Type<unsigned>() == !Type<int>()), "Ruh Roh");
static_assert((Type<int>() || Type<int8_t>()) != (Type<unsigned>() || Type<uint8_t>()), "Ruh Roh");
static_assert((Type<int>() || Type<int8_t>()) == !(Type<unsigned>() || Type<uint8_t>()), "Ruh Roh");
static_assert((Type<int>() || Type<int8_t>()) == (!Type<unsigned>() && !Type<uint8_t>()), "Ruh Roh");
static_assert(Type<int>() == (!Type<unsigned>()), "Ruh Roh");
static_assert(Type<int>() == Type<typing::Any>(), "Ruh Roh");
static_assert(Type<int>() != Type<typing::None>(), "Ruh Roh");
static_assert(Type<int>() == !Type<typing::None>(), "Ruh Roh");
static_assert(!(Type<int>() == Type<typing::None>()), "Ruh Roh");
using std::cout;
cout << std::boolalpha;
cout << (!(Type<int>() == !Type<int>())) << '\n';
// If uncommented, the next line fails to compile with
// "no matching function call" because `g` takes only `!int`
// g<int>();
g<unsigned>();
Int<int> i;
Int<int8_t> i8;
IntPair<int, int8_t> i_i8;
// If uncommented, the next line fails to compile with
// assertion that uint8_t is not a signed int type
// IntPair<int, uint8_t> i_u8;
f<int, int8_t>();
return 0;
}