[llvm-dev] RFC: General purpose type-safe formatting library

Chandler Carruth via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 11 23:29:31 PDT 2016


I'm generally favorable on the core idea of having a type-safe and friendly
format-string-like formatting utility. Somewhat minor comments below:

On Tue, Oct 11, 2016 at 6:22 PM Zachary Turner via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> The high level design of my library is borrowed heavily from C#.
>

My only big hesitation here is that the substitution specifier seems
heavily influenced by C#. I'd prefer to model this after a format string
syntax folks are fairly familiar with. IMO, Python's is probably the best
bet here and has had a lot of hammering on it over the years. So I'd
suggest that the pattern syntax be mapped to be as similar to Python's as
possible or at least built on top of it.

1. os << format_string("Test");   // writes "test"
> 2. os << format_string("{0}", 7);  // writes "7"
>

The "<< format_string(..." is ... really verbose for me. It also makes me
strongly feel like this produces a string rather than a streamable entity.

I'm not a huge fan of streaming, but if we want to go this route, I'd very
much like to keep the syntax short and sweet. "format" is pretty great for
that. If this is going to fully subsume its use cases, can we eventually
get that to be the name?

(While I don't like streaming, I'm not trying to fight that battle here...)

Also, you should probably look at what is quickly becoming a popular C++
library in this space: https://github.com/fmtlib/fmt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161012/84f26c2c/attachment.html>


More information about the llvm-dev mailing list