C++ Logo

std-proposals

Advanced search

Re: Fwd: Internal fill *not* considered harmful (re: P1652)

From: Matthew Woehlke <mwoehlke.floss_at_[hidden]>
Date: Tue, 25 Jun 2019 15:25:03 -0400
On 25/06/2019 15.03, Victor Zverovich via Std-Proposals wrote:
> All but one uses of `=` with Folly Format or {fmt} that I've seen
> (including an extensive search in one of the biggest C++ codebases) could
> have been rewritten in a simpler way with the `0` flag. The only case that
> I've found where `=` was used with fill other than `0` was a Folly Format
> test case.
>
> Do you have any use case for `=` that you cannot express by other means?

How does one readily achieve this?

  std::string s1 = std::format("{: =6}", 42); // s1 == "+ 42"
  std::string s2 = std::format("{: =6}", -5); // s2 == "- 5"

That was my first assumption as to why one would want to use internal
alignment in the first place...

> The `=` alignment in P0645 comes from Python where it's pretty broken:
>
> >>> "{: =+#8x}".format(4)
> '+0x 4'

I'm not sure I agree that's broken.

-- 
Matthew

Received on 2019-06-25 14:26:55