Statically forbid string ~ size_t ?

bcs bcs at example.com
Thu Oct 13 19:55:31 PDT 2011


On 10/13/2011 05:29 PM, Nick Sabalausky wrote:
> "Don"<nospam at nospam.com>  wrote in message
> news:j77p3i$1eac$1 at digitalmars.com...
>>
>> The problem is things like:
>> int i;
>> string s = "0x" ~ ('0' + x);
>> since char + int -->  int.
>>
>
> 1. Maybe it would be better to have "char + int -->  char"? Sounds much more
> sensible to me, although I haven't thought too much about it. When do you
> ever add a number to a code unit and *not* expect to end up with another
> code unit?

int i = 0;

foreach(c; somesrting) {
   i = i * 10;
   i = i + c;
}

>
> 2. I see nothing wrong with needing an explicit cast when going from int to
> char, even in that example. What we have now is a teeny, tiny, minor, minor,
> minor convenience for some not-particularly-common situations. And the cost
> for that negligable benefit is shit like this: "I have "~count~" apples" //
> Ka-boom  --  I want a compile error on shit like that (heck, even an
> implicit to!string would at least be an improvement over what it does now).
>
>


More information about the Digitalmars-d mailing list