01777777777777777777777 [std.conv.octal]

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 7 22:57:21 UTC 2022


On 4/7/22 4:18 PM, user1234 wrote:
> On Thursday, 7 April 2022 at 19:59:24 UTC, Steven Schveighoffer wrote:
>> Another problem I just realized:
>>
>> ```d
>>     auto x1 = octal!17777777777;
>>     auto x2 = octal!"17777777777";
>>     pragma(msg, typeof(x1)); // long
>>     pragma(msg, typeof(x2)); // int
>> ```
>>
>> Why? because `octal(T)` takes the type of `T`
>>
>> And there's no way to fix it. Because you'd want `octal!1L` to be 
>> long, so you can't just look at the value.
> 
> I dont see any real problem with x1 type because you can request to have 
> it as `int` without cast
> 
> ```
> int x1 = octal!17777777777;
> ```
> 
> 

Yes, but auto is convenient, template IFTI will not carry forward that 
ability to assign to an int, etc.

I'd say we just undocument (and don't deprecate) the numeric form. 
Anyone who uses it can continue to do so, and once the compiler stops 
suggesting using it, I can't see a good reason to do it.

-Steve


More information about the Digitalmars-d mailing list