alias not valid with ~

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 18 19:22:45 PST 2017


On Thursday, 19 January 2017 at 02:35:08 UTC, Ignacious wrote:
> But this is alias this, the whole point of alias this is to 
> treat the type as as the alias?

No, alias this is for subtyping. Similar to a child class, a 
subtype can be used as its parent type, but must be constructed.

class A {}
class B : A {}

A a = new B(); // legal, B will convert to A
B a = new A(); // illegal, A is not B

alias this is the same concept, just outside of class inheritance.

https://en.wikipedia.org/wiki/Subtyping

> Yet, logically, 3 is convertible to Y(3rd line above) and Y is 
> appendable to X.

Wrong. Implicit construction and implicit conversion are 
different concepts in theory and in practice in every language I 
know. You often want them separately as construction may need 
additional state, may just not be logical, and may have a 
different runtime cost than substitution.

D does not support implicit construction under any circumstance 
except the typesafe variadic syntax in function calls that take a 
single class.

(I'd like to add it, but Walter doesn't agree..)


More information about the Digitalmars-d-learn mailing list