[PATCH] D24686: [support] Some improvements to StringSwitch
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 3 11:16:00 PDT 2016
You can instead write this way.
auto Ret = StringSwitch<Optional<int>>(Str)
.Case("foo", 1)
...
.Default(None);
instead of
auto Ret = StringSwitch<int>(Str)
.Case("foo", 1)
...
.OrNone();
The former pattern is at least as readable as the latter (to me the former
is easier to read), so I don't see a strong reason to add a new method to
StringSwitch.
On Mon, Oct 3, 2016 at 11:07 AM, Zachary Turner <zturner at google.com> wrote:
> zturner added a comment.
>
> I don't think that will work.
>
> In https://reviews.llvm.org/D24686#559270, @ruiu wrote:
>
> > I wonder if we need `OrNone`. Isn't it equivalent to `.Default(None)`?
>
>
> It works if we add an additional overload of `Default()` like this:
>
> Optional<R> Default(llvm::NoneType N) const {
> if (Result)
> return *Result;
> return None;
> }
>
> If people prefer that I can go with that instead of `OrNone`
>
>
> https://reviews.llvm.org/D24686
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/61ad4773/attachment.html>
More information about the llvm-commits
mailing list