[PATCH] D24686: [support] Some improvements to StringSwitch

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 13:35:03 PDT 2016


Well, I don't have data points to make a decision, so if you like that way
I don't object. The other way would be to make it switchable, e.g.

  auto Ret = StringSwtich<T>(Str)
    .Case("case-sensitive", foo)
    .CaseInsensitive()
    .Case("case-insensitive", bar)
    .CaseSensitive()
    ...

but it's probably too much.

On Mon, Oct 3, 2016 at 1:30 PM, Zachary Turner <zturner at google.com> wrote:

> That is true, but it would make it impossible to have both case sensitive
> and case-insensitive cases in the same switch.  For example, the following
> is currently possible:
>
> StringSwitch<int>(s).Case("one").CaseLower("two");
>
> I'm not sure how useful this would be, but I see no reason not to allow
> it.  One idea might be to templatize the member function itself, and give
> it a default value of case sensitive.  But then you still have to write:
>
> StringSwitch<int>(s).Case<>("one").Case<false>("two");
>
> which might be awkward.  thoughts?
>
> On Mon, Oct 3, 2016 at 1:26 PM Rui Ueyama <ruiu at google.com> wrote:
>
>> It just comes to my mind that you could make StringSwitch
>> case-insensitive instead of adding case-insensitive versions of StartsWith,
>> Case and Cases. It'd probably be something like
>>
>>   auto Ret = StringSwtich<T>(Str, /*CaseInsensitive=*/true)
>>       .Case("foo", bar) //  "foo" is compared in the insensitive manner
>>       ...
>>
>> With this, you don't need to double the number of member functions.
>>
>> On Mon, Oct 3, 2016 at 1:15 PM, Zachary Turner <zturner at google.com>
>> wrote:
>>
>> zturner updated this revision to Diff 73327.
>> zturner added a comment.
>>
>> Unit tests for the case-sensitive versions were removed and submitted
>> separately.  The `Optional` variant of the function is removed and will be
>> submitted later.  This patch only contains case-insensitive versions of the
>> functions with associated unit tests.
>>
>>
>> https://reviews.llvm.org/D24686
>>
>> Files:
>>   include/llvm/ADT/StringSwitch.h
>>   unittests/ADT/StringSwitchTest.cpp
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/394399b2/attachment.html>


More information about the llvm-commits mailing list