File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -267,6 +267,14 @@ template <typename T> class Optional {
267
267
return hasValue () ? getValue () : std::forward<U>(value);
268
268
}
269
269
270
+ // / Apply a function to the value if present; otherwise return None.
271
+ template <class Function >
272
+ auto map (const Function &F) const
273
+ -> Optional<decltype(F(getValue()))> {
274
+ if (*this ) return F (getValue ());
275
+ return None;
276
+ }
277
+
270
278
#if LLVM_HAS_RVALUE_REFERENCE_THIS
271
279
T &&getValue() && { return std::move (Storage.getValue ()); }
272
280
T &&operator *() && { return std::move (Storage.getValue ()); }
@@ -275,6 +283,14 @@ template <typename T> class Optional {
275
283
T getValueOr (U &&value) && {
276
284
return hasValue () ? std::move (getValue ()) : std::forward<U>(value);
277
285
}
286
+
287
+ // / Apply a function to the value if present; otherwise return None.
288
+ template <class Function >
289
+ auto map (const Function &F) &&
290
+ -> Optional<decltype(F(std::move(*this ).getValue()))> {
291
+ if (*this ) return F (std::move (*this ).getValue ());
292
+ return None;
293
+ }
278
294
#endif
279
295
};
280
296
You can’t perform that action at this time.
0 commit comments