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

Zachary Turner via llvm-dev
Wed, 12 Oct 2016 13:11:36 -0000

In my current implementation, it's up to the format provider. If you have
an illegal format spec (eg {0;0}) it ignores it and prints the format spec
as a literal. We could also add an assert here in theory.

If/when we move to c++14, a constexpr StringRef implementation would allow
us to parse and validate the entire format string at compile time.

Since conciseness is one of the main goals of a library such as this, I
would hate to actively hamper this for more compile time checking. If you
write an invalid format spec presumably your test will fail since it will
ignore it

On Wed, Oct 12, 2016 at 2:34 AM Pavel Labath <labath at google.com> wrote:

> On 12 October 2016 at 05:26, Zachary Turner via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
> > os << format_string("Start: {0}, End: {1}, Elapsed:
{2:ms}", start, end,
> > start-end);
>
> What would happen if I accidentally type "ps" instead of
"ms" (I am
> assuming we will not support picoseconds here)?
>
> Will this abort at runtime?
>
> I would prefer if *all* arguments to the format were checkable at compile
> time:
> I.e. something like:
> os << "blah blah" <<
format<std::milli>(end-start) << "blah blah";
>
> I understand this may clash a bit with the desire for a compact
> representation, but maybe with some clever design we could achieve
> both?
>
> pl
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20161012/61834a37/attachment.html>