<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 11, 2016 at 11:15 PM Sean Silva <<a href="mailto:chisophugis@gmail.com">chisophugis@gmail.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="gmail_msg">This is awesome. +1<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Copying a time-tested design like C#'s (and which also Python uses) seems like a really sound approach.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Do you have any particular plans w.r.t. converting existing uses of the other formatting constructs? At the very least we can hopefully get rid of format_hex/format_hex_no_prefix since I don't think there are too many uses of those functions.</div></div></blockquote><div>I can certainly try, although when I did a quick grep I found 1,637 uses of llvm::format().  It's something we can work towards slowly, but I don't imagine I have the capacity to convert all of these by myself.  Getting rid of format_hex() could be a worthy first step though.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Also, Since the format string already can embed the surrounding literal strings, do you anticipate the use case where you would want to use `OS << format_string(...) << ...something else...`?</div><div class="gmail_msg">Would `print(OS, "....", ....)` make more sense?</div></div></blockquote><div>Perhaps.  I would argue that the whole reason we use << in the first place is *because* we don't have a real formatting function.  And when we do have one -- assuming it's designed correctly -- streaming operators become unnecessary / a thing of the past.  I can imagine a couple of different syntaxes.  </div><div><br></div><div>os.format(format_str, args...);   // format() is an instance method of raw_ostream.</div><div>T format_string<T>(format_str, args...);  // returns a T  (e.g. a std::string, or SmallString<N>)</div><div><br></div><div>T &formatf(T &t, format_str, args...);  // formats to the location specified by T, which could be a stream, std::string, SmallString, etc.  In practice this could be implemented by having the raw_ostream overload call os.format(format_str, args); and having the other versions create a raw_string_ostream or raw_svec_ostream and delegating to the stream version.</div></div></div>