@@ -37,24 +37,7 @@ class TThreadSafeOptional {
37
37
}
38
38
}
39
39
40
- TThreadSafeOptional& operator =(const TThreadSafeOptional& other) {
41
- if (this == &other) {
42
- return *this ;
43
- }
44
-
45
- const bool has = other.Defined .load (std::memory_order_acquire);
46
- if (Has ()) {
47
- Ptr ()->~T ();
48
- Defined.store (false , std::memory_order_release);
49
- }
50
-
51
- if (has) {
52
- ::new (Ptr ()) T (*other.Ptr ());
53
- Defined.store (true , std::memory_order_release);
54
- }
55
-
56
- return *this ;
57
- }
40
+ TThreadSafeOptional& operator =(const TThreadSafeOptional& other) = delete ;
58
41
59
42
TThreadSafeOptional (TThreadSafeOptional&& other) noexcept {
60
43
const bool has = other.Defined .load (std::memory_order_acquire);
@@ -69,12 +52,8 @@ class TThreadSafeOptional {
69
52
return *this ;
70
53
}
71
54
55
+ AFL_VERIFY (!Has ());
72
56
const bool has = other.Defined .load (std::memory_order_acquire);
73
- if (Has ()) {
74
- Ptr ()->~T ();
75
- Defined.store (false , std::memory_order_release);
76
- }
77
-
78
57
if (has) {
79
58
::new (Ptr ()) T (std::move (*other.Ptr ()));
80
59
Defined.store (true , std::memory_order_release);
@@ -83,29 +62,16 @@ class TThreadSafeOptional {
83
62
return *this ;
84
63
}
85
64
86
- void Reset () {
87
- if (Has ()) {
88
- Ptr ()->~T ();
89
- Defined.store (false , std::memory_order_release);
90
- }
91
- }
65
+ void Reset () = delete;
92
66
93
67
void Set (const T& value) {
94
- if (Has ()) {
95
- Ptr ()->~T ();
96
- Defined.store (false , std::memory_order_release);
97
- }
98
-
68
+ AFL_VERIFY (!Has ());
99
69
::new (Ptr ()) T (value);
100
70
Defined.store (true , std::memory_order_release);
101
71
}
102
72
103
73
void Set (T&& value) {
104
- if (Has ()) {
105
- Ptr ()->~T ();
106
- Defined.store (false , std::memory_order_release);
107
- }
108
-
74
+ AFL_VERIFY (!Has ());
109
75
::new (Ptr ()) T (std::move (value));
110
76
Defined.store (true , std::memory_order_release);
111
77
}
0 commit comments