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

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 22 14:19:00 PDT 2016


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.

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/20491d38/attachment.html>


More information about the llvm-commits mailing list