cat > enh.d << CODE
struct IPv4Addr
{
alias IPAddr this; // alias type constructor for implicit conversion
}
// either IPv4 or IPv6
struct IPAddr
{
this(IPv4Addr) {}
}
void func(IPAddr)
{
}
unittest
{
func(IPv4Addr());
}
CODE
dmd -c -unittest enh.d
----
enh.d(3): Error: IPAddr is not a member of IPv4Addr
----
At the moment alias this for implicit conversions needs a dummy member method.
When you already have `IPAddr(IPv4Addr.init)` it's somewhat annoying to add `IPv4Addr.init.toIPAddr` to the public API, only to support implicit conversions. Now there are 2 ways to do the same thing, sth. that's usually to be avoided in API design.
Alias-thising a free function or type would be resolved like `var.func` calls, and according to the current alias this rules.
Obviously this should be coordinated with the multiple alias this work.
Comment #1 by robert.schadek — 2024-12-13T18:54:55Z