<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 3, 2016 at 11:24 AM, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><span class=""><div dir="ltr">On Mon, Oct 3, 2016 at 11:16 AM Rui Ueyama <<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_6086483094350391897gmail_msg">You can instead write this way.<div class="m_6086483094350391897gmail_msg"><br class="m_6086483094350391897gmail_msg"></div><div class="m_6086483094350391897gmail_msg">auto Ret = StringSwitch<Optional<int>>(<wbr>Str)</div><div class="m_6086483094350391897gmail_msg">    .Case("foo", 1)</div><div class="m_6086483094350391897gmail_msg">    ...</div><div class="m_6086483094350391897gmail_msg">    .Default(None);</div><div class="m_6086483094350391897gmail_msg"><br class="m_6086483094350391897gmail_msg"></div><div class="m_6086483094350391897gmail_msg">instead of</div><div class="m_6086483094350391897gmail_msg"><br class="m_6086483094350391897gmail_msg"></div><div class="m_6086483094350391897gmail_msg"><div class="m_6086483094350391897gmail_msg">auto Ret = StringSwitch<int>(Str)</div><div class="m_6086483094350391897gmail_msg">    .Case("foo", 1)</div><div class="m_6086483094350391897gmail_msg">    ...</div><div class="m_6086483094350391897gmail_msg">    .OrNone();</div></div><div class="m_6086483094350391897gmail_msg"><br class="m_6086483094350391897gmail_msg"></div><div class="m_6086483094350391897gmail_msg">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.</div></div></blockquote><div><br></div></span><div>Ahh.   I guess the concern I have there is people might not even think to do that.  I guess it's obvious in hindsight but I didn't think of using a different type than the one I wanted as the argument to StringSwitch.  Having an OrNone() method makes it kind of explicit in the interface of the class that this is supported.</div></div></div>
</blockquote></div><br></div><div class="gmail_extra">I think my concern is that before this patch when you see a line starting with</div><div class="gmail_extra"><br></div><div class="gmail_extra">  auto Ret = StringSwitch<T>(...</div><div class="gmail_extra"><br></div><div class="gmail_extra">you are sure that Ret is of type T, but with this this can implicitly be Optional<T> if it ends with OrNone() which I think probably be too subtle.</div></div>