implicit construction operator
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Feb 26 23:33:48 UTC 2018
On Mon, Feb 26, 2018 at 09:45:03PM +0000, TheFlyingFiddle via Digitalmars-d wrote:
> On Monday, 26 February 2018 at 21:30:09 UTC, aliak wrote:
> > On Monday, 26 February 2018 at 19:32:44 UTC, ketmar wrote:
> > > WebFreak001 wrote:
> > And if that's also a no no, how about char -> int. Or int -> float?
> > Is ok?
> >
> > Maybe there're some valid arguments, to disallow it *completely*
> > though?
> >
> > Cheers
>
> I would be very happy if char -> int and int -> float was not implicit.
Yeah, implicit char -> int is totally evil, and should never have gotten
into the language in the first place. To wit:
void foo(dchar ch) {
backup_files();
}
void foo(byte b) {
format_disk();
}
foo('a'); // guess which one gets called.
> This has happened to me enough times that i remember it:
>
> float a = some_int / some_other_int; //ops i don't think this was what I wanted.
> constrast
> float a = some_int.to!float / some_other_int.to!float; //ugly but at-least its clear.
Actually, since operations involving float are "infectious", all you
need is:
float a = some_int.to!float / some_other_int;
> Not really a big deal (and auto kind of ruins it) but it would make
> stuff consistent between user types and built in ones.
Not sure what you mean here. In a user type, if opBinary!"/" returns an
int, then you still have the same problem.
T
--
He who laughs last thinks slowest.
More information about the Digitalmars-d
mailing list