@@ -72,7 +72,7 @@ template <typename T, bool = (llvm::is_trivially_copy_constructible<T>::value &&
72
72
class OptionalStorage {
73
73
union {
74
74
char empty;
75
- T value ;
75
+ T val ;
76
76
};
77
77
bool hasVal;
78
78
@@ -83,22 +83,22 @@ class OptionalStorage {
83
83
84
84
constexpr OptionalStorage (OptionalStorage const &other) : OptionalStorage() {
85
85
if (other.hasValue ()) {
86
- emplace (other.value );
86
+ emplace (other.val );
87
87
}
88
88
}
89
89
constexpr OptionalStorage (OptionalStorage &&other) : OptionalStorage() {
90
90
if (other.hasValue ()) {
91
- emplace (std::move (other.value ));
91
+ emplace (std::move (other.val ));
92
92
}
93
93
}
94
94
95
95
template <class ... Args>
96
96
constexpr explicit OptionalStorage (in_place_t , Args &&... args)
97
- : value (std::forward<Args>(args)...), hasVal(true ) {}
97
+ : val (std::forward<Args>(args)...), hasVal(true ) {}
98
98
99
99
void reset () noexcept {
100
100
if (hasVal) {
101
- value .~T ();
101
+ val .~T ();
102
102
hasVal = false ;
103
103
}
104
104
}
@@ -107,39 +107,39 @@ class OptionalStorage {
107
107
108
108
T &getValue () LLVM_LVALUE_FUNCTION noexcept {
109
109
assert (hasVal);
110
- return value ;
110
+ return val ;
111
111
}
112
112
constexpr T const &getValue () const LLVM_LVALUE_FUNCTION noexcept {
113
113
assert (hasVal);
114
- return value ;
114
+ return val ;
115
115
}
116
116
#if LLVM_HAS_RVALUE_REFERENCE_THIS
117
117
T &&getValue() && noexcept {
118
118
assert (hasVal);
119
- return std::move (value );
119
+ return std::move (val );
120
120
}
121
121
#endif
122
122
123
123
template <class ... Args> void emplace (Args &&... args) {
124
124
reset ();
125
- ::new ((void *)std::addressof (value )) T (std::forward<Args>(args)...);
125
+ ::new ((void *)std::addressof (val )) T (std::forward<Args>(args)...);
126
126
hasVal = true ;
127
127
}
128
128
129
129
OptionalStorage &operator =(T const &y) {
130
130
if (hasValue ()) {
131
- value = y;
131
+ val = y;
132
132
} else {
133
- ::new ((void *)std::addressof (value )) T (y);
133
+ ::new ((void *)std::addressof (val )) T (y);
134
134
hasVal = true ;
135
135
}
136
136
return *this ;
137
137
}
138
138
OptionalStorage &operator =(T &&y) {
139
139
if (hasValue ()) {
140
- value = std::move (y);
140
+ val = std::move (y);
141
141
} else {
142
- ::new ((void *)std::addressof (value )) T (std::move (y));
142
+ ::new ((void *)std::addressof (val )) T (std::move (y));
143
143
hasVal = true ;
144
144
}
145
145
return *this ;
@@ -148,9 +148,9 @@ class OptionalStorage {
148
148
OptionalStorage &operator =(OptionalStorage const &other) {
149
149
if (other.hasValue ()) {
150
150
if (hasValue ()) {
151
- value = other.value ;
151
+ val = other.val ;
152
152
} else {
153
- ::new ((void *)std::addressof (value )) T (other.value );
153
+ ::new ((void *)std::addressof (val )) T (other.val );
154
154
hasVal = true ;
155
155
}
156
156
} else {
@@ -162,9 +162,9 @@ class OptionalStorage {
162
162
OptionalStorage &operator =(OptionalStorage &&other) {
163
163
if (other.hasValue ()) {
164
164
if (hasValue ()) {
165
- value = std::move (other.value );
165
+ val = std::move (other.val );
166
166
} else {
167
- ::new ((void *)std::addressof (value )) T (std::move (other.value ));
167
+ ::new ((void *)std::addressof (val )) T (std::move (other.val ));
168
168
hasVal = true ;
169
169
}
170
170
} else {
@@ -177,7 +177,7 @@ class OptionalStorage {
177
177
template <typename T> class OptionalStorage <T, true > {
178
178
union {
179
179
char empty;
180
- T value ;
180
+ T val ;
181
181
};
182
182
bool hasVal = false ;
183
183
@@ -194,11 +194,11 @@ template <typename T> class OptionalStorage<T, true> {
194
194
195
195
template <class ... Args>
196
196
constexpr explicit OptionalStorage (in_place_t , Args &&... args)
197
- : value (std::forward<Args>(args)...), hasVal(true ) {}
197
+ : val (std::forward<Args>(args)...), hasVal(true ) {}
198
198
199
199
void reset () noexcept {
200
200
if (hasVal) {
201
- value .~T ();
201
+ val .~T ();
202
202
hasVal = false ;
203
203
}
204
204
}
@@ -207,39 +207,39 @@ template <typename T> class OptionalStorage<T, true> {
207
207
208
208
T &getValue () LLVM_LVALUE_FUNCTION noexcept {
209
209
assert (hasVal);
210
- return value ;
210
+ return val ;
211
211
}
212
212
constexpr T const &getValue () const LLVM_LVALUE_FUNCTION noexcept {
213
213
assert (hasVal);
214
- return value ;
214
+ return val ;
215
215
}
216
216
#if LLVM_HAS_RVALUE_REFERENCE_THIS
217
217
T &&getValue() && noexcept {
218
218
assert (hasVal);
219
- return std::move (value );
219
+ return std::move (val );
220
220
}
221
221
#endif
222
222
223
223
template <class ... Args> void emplace (Args &&... args) {
224
224
reset ();
225
- ::new ((void *)std::addressof (value )) T (std::forward<Args>(args)...);
225
+ ::new ((void *)std::addressof (val )) T (std::forward<Args>(args)...);
226
226
hasVal = true ;
227
227
}
228
228
229
229
OptionalStorage &operator =(T const &y) {
230
230
if (hasValue ()) {
231
- value = y;
231
+ val = y;
232
232
} else {
233
- ::new ((void *)std::addressof (value )) T (y);
233
+ ::new ((void *)std::addressof (val )) T (y);
234
234
hasVal = true ;
235
235
}
236
236
return *this ;
237
237
}
238
238
OptionalStorage &operator =(T &&y) {
239
239
if (hasValue ()) {
240
- value = std::move (y);
240
+ val = std::move (y);
241
241
} else {
242
- ::new ((void *)std::addressof (value )) T (std::move (y));
242
+ ::new ((void *)std::addressof (val )) T (std::move (y));
243
243
hasVal = true ;
244
244
}
245
245
return *this ;
@@ -292,9 +292,13 @@ template <typename T> class Optional {
292
292
293
293
constexpr const T *getPointer () const { return &Storage.getValue (); }
294
294
T *getPointer () { return &Storage.getValue (); }
295
+ constexpr const T &value () const LLVM_LVALUE_FUNCTION {
296
+ return Storage.getValue ();
297
+ }
295
298
constexpr const T &getValue () const LLVM_LVALUE_FUNCTION {
296
299
return Storage.getValue ();
297
300
}
301
+ T &value () LLVM_LVALUE_FUNCTION { return Storage.getValue (); }
298
302
T &getValue () LLVM_LVALUE_FUNCTION { return Storage.getValue (); }
299
303
300
304
constexpr explicit operator bool () const { return hasValue (); }
@@ -307,8 +311,8 @@ template <typename T> class Optional {
307
311
T &operator *() LLVM_LVALUE_FUNCTION { return getValue (); }
308
312
309
313
template <typename U>
310
- constexpr T getValueOr (U &&value ) const LLVM_LVALUE_FUNCTION {
311
- return hasValue () ? getValue () : std::forward<U>(value );
314
+ constexpr T getValueOr (U &&alt ) const LLVM_LVALUE_FUNCTION {
315
+ return hasValue () ? getValue () : std::forward<U>(alt );
312
316
}
313
317
314
318
// / Apply a function to the value if present; otherwise return None.
@@ -320,12 +324,13 @@ template <typename T> class Optional {
320
324
}
321
325
322
326
#if LLVM_HAS_RVALUE_REFERENCE_THIS
327
+ T &&value() && { return std::move (Storage.getValue ()); }
323
328
T &&getValue() && { return std::move (Storage.getValue ()); }
324
329
T &&operator *() && { return std::move (Storage.getValue ()); }
325
330
326
331
template <typename U>
327
- T getValueOr (U &&value ) && {
328
- return hasValue () ? std::move (getValue ()) : std::forward<U>(value );
332
+ T getValueOr (U &&alt ) && {
333
+ return hasValue () ? std::move (getValue ()) : std::forward<U>(alt );
329
334
}
330
335
331
336
// / Apply a function to the value if present; otherwise return None.
0 commit comments