[Issue 5747] cannot cast away shared if opCast defined
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Dec 11 22:20:25 PST 2013
https://d.puremagic.com/issues/show_bug.cgi?id=5747
--- Comment #8 from Jonathan M Davis <jmdavisProg at gmx.com> 2013-12-11 22:19:54 PST ---
Like monarchdodra, I question the wisdom in overloading the cast operator for
type qualifiers. Maybe it's useful and needed, but 99.99% of the time, having
to have overloads to restore qualifier casts on top of what opCast was
overloaded for is extremely annoying. Why should the built-in casts suddenly
stop working just because I added a cast to a completely different type? That
seems like a horrible idea to me.
Also, if the built-in casts are hidden, how are you supposed to even create
overloads to put them back? For instance, to cast from mutable to immutable
requires a built-in cast. You can't duplicate that on your own, which at
present means that if you overload opCast, it becomes impossible to cast from
mutable to immutable. The same goes with any other qualifier conversion that
can't be done implicitly.
If someone defines an overload for opCast which simply does a qualifier cast -
e.g. const(typeof(this)) opCast(T) if(T == typeof(this)) {...} - then that
should override the built-in cast, but if there is no overload for opCast which
replaces a built-in cast, then the built-in cast should still be useable.
That's the only way to do this that makes sense to me.
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list