[PATCH] D24842: Add StringRef {take, drop} x {_while, _until}

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 14:36:57 PDT 2016


On Thu, Sep 22, 2016 at 2:19 PM, Zachary Turner <zturner at google.com> wrote:

> How am I supposed to use this?  If I write this:
>
>     template <typename Ret, typename Param>
>     LLVM_ATTRIBUTE_UNUSED_RESULT StringRef drop_until(function_ref<Ret(Param)>
> F) const {
>
> And call it like this:
>
>   StringRef Taken = Test.take_while(::isdigit);
>
> Then I get an error that the template types cannot be deduced.  I don't
> want to hardcode it to function_ref<bool(char)> because functions like
> is_digit etc exist and should be allowed.
>

Eh, I'd just hardcode bool(char) as it makes the signature of what I'm
supposed to give it obvious and isdigit could just be wrapped in a trivial
little lambda.  Besides, isigit is evil because it is locale sensitive :P


>
> On Thu, Sep 22, 2016 at 2:06 PM David Majnemer <david.majnemer at gmail.com>
> wrote:
>
>> majnemer added inline comments.
>>
>> ================
>> Comment at: include/llvm/ADT/StringRef.h:499-511
>> @@ -498,1 +498,15 @@
>>
>> +    template <typename Func>
>> +    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef take_while(Func F) const {
>> +      StringRef S(*this);
>> +      while (!S.empty()) {
>> +        if (!F(S.front()))
>> +          break;
>> +        S = S.drop_front();
>> +      }
>> +      return drop_back(S.size());
>> +    }
>> +
>> +    template <typename Func>
>> +    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef take_until(Func F) const {
>> +      StringRef S(*this);
>> ----------------
>> davide wrote:
>> > Oh, and maybe if you can add a comment at the beginning of each
>> function (e.g. as consume_front() already does) it would be good.
>> Can you use function_ref instead?
>>
>>
>> https://reviews.llvm.org/D24842
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160922/e4491b00/attachment-0001.html>


More information about the llvm-commits mailing list