| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#pragma once |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
namespace panda { |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
template struct optional { |
|
6
|
40
|
|
|
|
|
|
~optional() { reset(); } |
|
7
|
|
|
|
|
|
|
|
|
8
|
5
|
|
|
|
|
|
optional() : nullable_val(nullptr) {} |
|
9
|
|
|
|
|
|
|
|
|
10
|
18
|
50
|
|
|
|
|
optional(const T& val) : nullable_val(new (storage) T(val)) {} |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
6
|
50
|
|
|
|
|
optional(const optional& oth) : nullable_val(oth ? new (storage) T(*oth) : nullptr) {} |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
optional& operator=(optional const& oth) { |
|
15
|
|
|
|
|
|
|
if (&oth != this) { |
|
16
|
|
|
|
|
|
|
reset(); |
|
17
|
|
|
|
|
|
|
if (oth) |
|
18
|
|
|
|
|
|
|
nullable_val = new (storage) T(*oth); |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
return *this; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
optional& operator=(const T& val) { |
|
24
|
|
|
|
|
|
|
reset(); |
|
25
|
|
|
|
|
|
|
nullable_val = new (storage) T(val); |
|
26
|
|
|
|
|
|
|
return *this; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
20
|
|
|
|
|
|
void reset() { |
|
30
|
20
|
50
|
|
|
|
|
if (nullable_val) |
|
|
|
100
|
|
|
|
|
|
|
31
|
15
|
|
|
|
|
|
nullable_val->~T(); |
|
32
|
20
|
|
|
|
|
|
nullable_val = nullptr; |
|
33
|
20
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
|
T& operator*() { return *nullable_val; } |
|
36
|
18
|
|
|
|
|
|
const T& operator*() const { return *nullable_val; } |
|
37
|
|
|
|
|
|
|
T* operator->() { return nullable_val; } |
|
38
|
|
|
|
|
|
|
const T* operator->() const { return nullable_val; } |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
T value_or(const T& default_val) const { return nullable_val ? *nullable_val : default_val; } |
|
41
|
|
|
|
|
|
|
|
|
42
|
8
|
|
|
|
|
|
T value() const { return *nullable_val; } |
|
43
|
|
|
|
|
|
|
|
|
44
|
40
|
|
|
|
|
|
explicit operator bool() const { return nullable_val != nullptr; } |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
private: |
|
47
|
|
|
|
|
|
|
T* nullable_val; |
|
48
|
|
|
|
|
|
|
alignas(alignof(T)) char storage[sizeof(T)]; |
|
49
|
|
|
|
|
|
|
}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
template struct optional_tools { |
|
52
|
|
|
|
|
|
|
using type = optional; |
|
53
|
|
|
|
|
|
|
static type default_value () { return type{}; } |
|
54
|
|
|
|
|
|
|
}; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
template <> struct optional_tools { |
|
57
|
|
|
|
|
|
|
using type = void; |
|
58
|
|
|
|
|
|
|
static void default_value () {} |
|
59
|
|
|
|
|
|
|
}; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
template inline constexpr bool operator== (const optional& lhs, const optional& rhs) { |
|
62
|
|
|
|
|
|
|
return (lhs && rhs) ? (*lhs == *rhs) : (lhs || rhs ? false : true); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
template inline constexpr bool operator!= (const optional& lhs, const optional& rhs) { return !operator==(lhs, rhs); } |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
template |
|
67
|
|
|
|
|
|
|
inline constexpr bool operator< (const optional& lhs, const optional& rhs) { |
|
68
|
|
|
|
|
|
|
return (lhs && rhs) ? (*lhs < *rhs) : (rhs ? true : false); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
template |
|
72
|
|
|
|
|
|
|
constexpr bool operator<= (const optional& lhs, const optional& rhs) { |
|
73
|
|
|
|
|
|
|
return (lhs && rhs) ? (*lhs < *rhs) : (lhs ? false : true); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
template |
|
77
|
|
|
|
|
|
|
constexpr bool operator> (const optional& lhs, const optional& rhs) { |
|
78
|
|
|
|
|
|
|
return (lhs && rhs) ? (*lhs < *rhs) : (lhs ? true : false); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
template |
|
82
|
|
|
|
|
|
|
constexpr bool operator>= (const optional& lhs, const optional& rhs) { |
|
83
|
|
|
|
|
|
|
return (lhs && rhs) ? (*lhs < *rhs) : (rhs ? false : true); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
template constexpr bool operator== (const optional& opt, const U& value) { return opt && *opt == value; } |
|
87
|
|
|
|
|
|
|
template constexpr bool operator== (const T& value, const optional& opt) { return opt && value == *opt; } |
|
88
|
|
|
|
|
|
|
template constexpr bool operator!= (const optional& opt, const U& value) { return !operator==(opt, value); } |
|
89
|
|
|
|
|
|
|
template constexpr bool operator!= (const T& value, const optional& opt) { return !operator==(value, opt); } |
|
90
|
|
|
|
|
|
|
template constexpr bool operator< (const optional& opt, const U& value) { return opt ? *opt < value : true; } |
|
91
|
|
|
|
|
|
|
template constexpr bool operator< (const T& value, const optional& opt) { return opt && value < *opt; } |
|
92
|
|
|
|
|
|
|
template constexpr bool operator<= (const optional& opt, const U& value) { return opt ? *opt <= value : true; } |
|
93
|
|
|
|
|
|
|
template constexpr bool operator<= (const T& value, const optional& opt) { return opt && value <= *opt; } |
|
94
|
|
|
|
|
|
|
template constexpr bool operator> (const optional& opt, const U& value) { return opt && *opt > value; } |
|
95
|
|
|
|
|
|
|
template constexpr bool operator> (const T& value, const optional& opt) { return opt ? value > *opt : true; } |
|
96
|
|
|
|
|
|
|
template constexpr bool operator>= (const optional& opt, const U& value) { return opt && *opt >= value; } |
|
97
|
|
|
|
|
|
|
template constexpr bool operator>= (const T& value, const optional& opt) { return opt ? value >= *opt : true; } |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |