A StringSwitch does not always have a default value. In these cases, you
can currently achieve the same using the following, which is pretty
ugly:
std::optional<InnerT> Foo = llvm::StringSwitch<std::optional<InnerT>>(str) .Case("foo", std::optional(InnerT(...))) .Default(std::nullopt);
This commit allows you to achieve the same using the following, which I
think makes the intent a lot clearer (and avoids a nested optional
internally):
std::optional<InnerT> Foo = llvm::StringSwitch<InnerT>(str) .Case("foo", InnerT(...)) .AsOptional();
Would that work? Note that Result is std::optional<T> and std::optional has a converting move constructor.