October 14, 2011 Re: Statically forbid string ~ size_t ? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 14/10/11 12:23 PM, Steven Schveighoffer wrote:
> On Thu, 13 Oct 2011 18:34:35 -0400, Don <nospam@nospam.com> wrote:
>
>> On 13.10.2011 23:07, bearophile wrote:
>>> I think that int+char is acceptable in D, but string~size_t is not
>>> good. I think this is bug prone (especially given the expectations of
>>> programmers coming from other languages). So I suggest to statically
>>> disallow string~size_t. string~char, string~dchar, and string~string
>>> are of course OK.
>>>
>>> So far I have written no enhancement request/bug report on this
>>> because I am not so sure...
>>
>> The problem is things like:
>> int i;
>> string s = "0x" ~ ('0' + x);
>> since char + int --> int.
>>
>
> string s = "0x" ~ cast(char)('0' + x);
>
> Problem solved.
>
> -Steve
Agreed.
I don't think it's worth violating fundamental principles for the sake of a minor convenience in relatively uncommon situations.
Honestly, I'd like to get rid of implicit conversions altogether, but maybe that's just me...
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply