[PATCH] D140221: [Support] Add StringSwitch::AsOptional

Sam Elliott via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 16 12:46:49 PST 2022


lenary added inline comments.


================
Comment at: llvm/include/llvm/ADT/StringSwitch.h:189-192
+    if (Result)
+      return std::optional(std::move(*Result));
+
+    return std::nullopt;
----------------
barannikov88 wrote:
> Would that work? Note that `Result` is `std::optional<T>` and std::optional has a converting move constructor.
> 
Maybe. I'm not super familiar with move semantics, but i can see how that should work based on the description at cppreference.com, and I like that it's simpler. I'll try it with the follow-on patch that uses it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140221/new/

https://reviews.llvm.org/D140221



More information about the llvm-commits mailing list