Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 09:33:40 UTC, ixid wrote: 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. +1 If

Re: Preventing implicit conversion

2015-11-05 Thread ixid via Digitalmars-d-learn
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

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
And I want to have small number litterals automatically choosing the smallest fitting type. If I write ubyte b = 1u; auto c = b + 1u; I expect the 1u to be of type ubyte - and also c.

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 13:23:34 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: ubyte b = 1u; auto c = b + 1u; I expect the 1u to be of type ubyte - and also c. This won't work because of the one-expression rule. In the

Re: Preventing implicit conversion

2015-11-05 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Thursday, 5 November 2015 at 22:15:46 UTC, Dominikus Dittes Scherkl wrote: On Thursday, 5 November 2015 at 13:23:34 UTC, Adam D. Ruppe wrote: On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: ubyte d = b + (ubyte)1; Sorry, should of course be: ubyte d = b +

Re: Preventing implicit conversion

2015-11-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 05, 2015 09:33:39 ixid via Digitalmars-d-learn wrote: > 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

Re: Preventing implicit conversion

2015-11-05 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 5 November 2015 at 10:07:30 UTC, Dominikus Dittes Scherkl wrote: And I want to have small number litterals automatically choosing the smallest fitting type. It does, that's the value range propagation at work. Inside one expression, if the compiler can prove it fits in a smaller

Re: Preventing implicit conversion

2015-11-04 Thread ixid via Digitalmars-d-learn
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

Re: Preventing implicit conversion

2015-11-04 Thread Maxim Fomin via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 21:22:04 UTC, ixid 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

Re: Preventing implicit conversion

2015-11-04 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: Preventing implicit conversion

2015-11-04 Thread Maxim Fomin via Digitalmars-d-learn
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.

Re: Preventing implicit conversion

2015-11-04 Thread ixid via Digitalmars-d-learn
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? Also does this not seem inconsistent: ushort a = ushort.max, b = ushort.max; a += b; // Compiles fine a = a + b; // Error:

Preventing implicit conversion

2015-11-04 Thread ixid via Digitalmars-d-learn
Is there an elegant way of avoiding implicit conversion to int when you're using shorter types?

Re: Preventing implicit conversion

2015-11-04 Thread Daniel Kozak via Digitalmars-d-learn
V Wed, 04 Nov 2015 14:27:45 + ixid via Digitalmars-d-learn napsáno: > Is there an elegant way of avoiding implicit conversion to int > when you're using shorter types? http://dlang.org/phobos/std_typecons.html#.Typedef

Re: Preventing implicit conversion

2015-11-04 Thread ixid via Digitalmars-d-learn
On Wednesday, 4 November 2015 at 17:26:04 UTC, Daniel Kozak wrote: V Wed, 04 Nov 2015 14:27:45 + ixid via Digitalmars-d-learn napsáno: Is there an elegant way of avoiding implicit conversion to int when you're using shorter types?