<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 22, 2016 at 2:19 PM, Zachary Turner <span dir="ltr"><<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">How am I supposed to use this?  If I write this:<div><br></div><div><div>    template <typename Ret, typename Param></div><div>    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef drop_until(function_ref<Ret(<wbr>Param)> F) const {</div></div><div><br></div><div>And call it like this:</div><div><br></div><div><div>  StringRef Taken = Test.take_while(::isdigit);</div></div><div><br></div><div>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.</div></div></blockquote><div><br></div><div>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</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5"><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 22, 2016 at 2:06 PM David Majnemer <<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">majnemer added inline comments.<br>
<br>
================<br>
Comment at: include/llvm/ADT/StringRef.h:<wbr>499-511<br>
@@ -498,1 +498,15 @@<br>
<br>
+    template <typename Func><br>
+    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef take_while(Func F) const {<br>
+      StringRef S(*this);<br>
+      while (!S.empty()) {<br>
+        if (!F(S.front()))<br>
+          break;<br>
+        S = S.drop_front();<br>
+      }<br>
+      return drop_back(S.size());<br>
+    }<br>
+<br>
+    template <typename Func><br>
+    LLVM_ATTRIBUTE_UNUSED_RESULT StringRef take_until(Func F) const {<br>
+      StringRef S(*this);<br>
----------------<br>
davide wrote:<br>
> 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.<br>
Can you use function_ref instead?<br>
<br>
<br>
<a href="https://reviews.llvm.org/D24842" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D24842</a><br>
<br>
<br>
<br>
</blockquote></div>
</div></div></blockquote></div><br></div></div>