operator "~" does not check type?

Steven Schveighoffer schveiguy at yahoo.com
Wed Oct 12 07:26:07 PDT 2011


On Wed, 12 Oct 2011 09:46:57 -0400, Trass3r <un at known.com> wrote:

>> I believe that the primary reasoning for allowing the implicit  
>> conversion
>> between int and dchar is so that code like this
>>
>> dchar c = 'a' + 7;
>
> That's a '+' though, not a '~'.

Jonathan meant this better example ;)

string s = "hello";
s ~= 'a' + 7;

> I think it shouldn't be allowed with ~ since it's misleading.
> Newbies would probably expect "abc" ~ 10 to yield "abc10" rather than  
> the odd "abc\n".

100% agree.  Requiring a cast in order to convert to dchar is a small  
price to pay (not that common to do arithmetic with characters) for  
avoiding surprising compilations.

-Steve


More information about the Digitalmars-d-learn mailing list