implicit conversion
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Aug 12 08:39:08 PDT 2014
On Tuesday, 12 August 2014 at 14:26:46 UTC, Jonathan M Davis via
Digitalmars-d-learn wrote:
> AFAIK, the only time that the implicit conversion would take
> place is when the
> type is being used in a situation where it doesn't work
> directly but where the
> aliased type is used. In that case, the compiler sees the
> accepted types and
> sees that the type can implicitly convert to one of the
> accepted types and
> thus does the conversion. So, it knows that the conversion will
> work before it
> even does it. The compiler never attempts to do the conversion
> just to see
> whether it will work, which is essentially what it would have
> to do when
> attempting to use the type with a templated function. You can
> certainly create
> an enhancement request for such behavior, but I have no idea
> how likely it is
> get implemented. There are currently _no_ cases where the
> compiler does
> anything with template instantiations to try and make them pass
> if simply
> trying to instantiate them with the given type failed.
>
> - Jonathan M Davis
What I mean is that this breaks the Liskov Substitution
Principle, which alias this should obey, as it denotes a subtype.
Since S!float has an alias this to float, it should behave as a
float in all circumstances where a float is expected; otherwise,
we've got a big problem with alias this on our hands.
More information about the Digitalmars-d-learn
mailing list