Preventing implicit conversion
ixid via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Nov 5 01:33:39 PST 2015
On Thursday, 5 November 2015 at 05:41:46 UTC, Jonathan M Davis
wrote:
> On Wednesday, November 04, 2015 21:22:02 ixid via
> Digitalmars-d-learn wrote:
>> On Wednesday, 4 November 2015 at 19:09:42 UTC, Maxim Fomin
>> wrote:
>> > On Wednesday, 4 November 2015 at 14:27:49 UTC, ixid wrote:
>> >> Is there an elegant way of avoiding implicit conversion to
>> >> int when you're using shorter types?
>> >
>> > Only with library solution. Implicit conversions are built
>> > into language.
>>
>> Doesn't that seem rather limiting and unnecessary?
>
> Why? You can't affect what conversions do and don't work for
> the built-in types in _any_ language that I've ever used, and
> I've never heard of a language that allowed anything like that.
> If you want different conversion rules, you need to create a
> user-defined type that defines the conversions you want. That's
> pretty normal.
>
> And AFAIK, there aren't very many folks trying to avoid the
> built-in implicit conversions in D, particularly since D
> eliminated the various implicit narrowing conversions that you
> get in C/C++.
>
> - Jonathan M Davis
In C++ I can add two shorts together without having to use a cast
to assign the result to one of the two shorts. It just seems
super clunky not to be able to do basic operations on basic types
without casts everywhere.
More information about the Digitalmars-d-learn
mailing list