Date: Tue, 25 Jun 2019 18:07:58 -0400
On 25/06/2019 16.03, Zhihao Yuan wrote:
> On Tuesday, June 25, 2019 2:25 PM, Matthew Woehlke via Std-Proposals wrote:
>> 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...
>
> I think you meant "{:=+6}". I'm sure that any feature can be found
> to have some use if you derive its behavior from specification, the
> question is whether it worth the effort. Let's say we specified '='
> as an alignment that is "compatible" with the '0' flag as you
> suggests, can someone quickly tell the difference between {:0=6},
> {:=06}, {:0=06}, and {:06}?
{:0=6} → "-00123", "-00inf"
{:0=06} → "-00123", "-00inf"
{:=06} → "-00123", "- inf"
{:06} → "-00123", " -inf"
The "quick" rule would be: "you didn't want to use '0' as the fill
character". That will rarely be wanted. (Also, zero-padding will always
be superfluous if fill=='0' and align==internal.)
I think my example gave a more plausible use case; always put the sign
in the same column, but fill with spaces:
{: =6} → "- 123", "- inf"
{: =06} → "-00123", "- inf"
{: >06} → "-00123", " -inf"
I could also imagine wanting to use NBSP as the fill character.
(On a mostly unrelated note, I think many places where P0645 uses
"character", it really should be using "code point". I certainly expect
{:\xf0\x9f\x98\xbf<4} to produce "123😿" rather than throw an exception.
However, I'd probably argue that it is sufficiently obvious that it
ought to work that way that any necessary corrections could be handled
as defects. Besides, that's into the lovely area of behavior that
depends on the system locale, which is still a work in progress in the IS.)
> On the other hand, our proposed wording is forward-compatible with
> adding '=' as you suggest (correct me if I'm wrong). If people are
> motivated they can add it. But Rust people seem not :)
I suppose if you're arguing that we just never needed align=internal in
the first place, and everyone is okay with that, then... well, okay. I
just don't buy P1652r0 Problem 3 as the reason to get rid of it.
I do still think we "should" have:
{:>06} → "-00123", " inf"
{:<06} → "-00123", "inf "
{:0>6} → "00-123", "000inf"
{:0<6} → "-12300", "inf000"
{:0>06} → "-00123", "000inf"
{:0<06} → "-00123", "inf000"
(IOW, width starts with 0 is not the same as fill == '0'. IIUC, this
would be the case with P1652r0.)
> On Tuesday, June 25, 2019 2:25 PM, Matthew Woehlke via Std-Proposals wrote:
>> 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...
>
> I think you meant "{:=+6}". I'm sure that any feature can be found
> to have some use if you derive its behavior from specification, the
> question is whether it worth the effort. Let's say we specified '='
> as an alignment that is "compatible" with the '0' flag as you
> suggests, can someone quickly tell the difference between {:0=6},
> {:=06}, {:0=06}, and {:06}?
{:0=6} → "-00123", "-00inf"
{:0=06} → "-00123", "-00inf"
{:=06} → "-00123", "- inf"
{:06} → "-00123", " -inf"
The "quick" rule would be: "you didn't want to use '0' as the fill
character". That will rarely be wanted. (Also, zero-padding will always
be superfluous if fill=='0' and align==internal.)
I think my example gave a more plausible use case; always put the sign
in the same column, but fill with spaces:
{: =6} → "- 123", "- inf"
{: =06} → "-00123", "- inf"
{: >06} → "-00123", " -inf"
I could also imagine wanting to use NBSP as the fill character.
(On a mostly unrelated note, I think many places where P0645 uses
"character", it really should be using "code point". I certainly expect
{:\xf0\x9f\x98\xbf<4} to produce "123😿" rather than throw an exception.
However, I'd probably argue that it is sufficiently obvious that it
ought to work that way that any necessary corrections could be handled
as defects. Besides, that's into the lovely area of behavior that
depends on the system locale, which is still a work in progress in the IS.)
> On the other hand, our proposed wording is forward-compatible with
> adding '=' as you suggest (correct me if I'm wrong). If people are
> motivated they can add it. But Rust people seem not :)
I suppose if you're arguing that we just never needed align=internal in
the first place, and everyone is okay with that, then... well, okay. I
just don't buy P1652r0 Problem 3 as the reason to get rid of it.
I do still think we "should" have:
{:>06} → "-00123", " inf"
{:<06} → "-00123", "inf "
{:0>6} → "00-123", "000inf"
{:0<6} → "-12300", "inf000"
{:0>06} → "-00123", "000inf"
{:0<06} → "-00123", "inf000"
(IOW, width starts with 0 is not the same as fill == '0'. IIUC, this
would be the case with P1652r0.)
-- Matthew
Received on 2019-06-25 17:09:50