The DIP Process

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Feb 27 01:43:06 UTC 2019


On Tuesday, February 26, 2019 6:34:04 PM MST H. S. Teoh via Digitalmars-d 
wrote:
> On Tue, Feb 26, 2019 at 06:12:45PM -0700, Jonathan M Davis via 
Digitalmars-d wrote:
> > On Tuesday, February 26, 2019 5:53:51 PM MST Nicholas Wilson via
>
> > Digitalmars-d wrote:
> [...]
>
> > > FWIW Walter has said that if alias this had been proposed today that
> > > it would be rejected because it has too many nasty corner cases. I
> > > happen to believe alias this is awesome but I do see where he's
> > > coming from and I've been reviewing a lot of Razvan's PRs fixing
> > > those corner cases so I know they do exist. One of the points on the
> > > agenda for the DLF meeting at dconf is a review of the state of
> > > alias this.
> >
> > It's one of those features that's occasionally useful, but in general,
> > I'm inclined to think that it causes way more trouble than it's worth.
> > Honestly, implicit conversions in general tend to be problematic much
> > as they can be really nice to have sometimes. They're particularly bad
> > when templates get involved.
>
> [...]
>
> I'm a pretty heavy user of alias this, and would be quite unhappy if the
> present semantics were to change or become deprecated or otherwise cease
> being supported.  I understand there are some dark corner cases where
> it's not at all obvious what the "correct" behaviour is, but still,
> alias this does offer significant value for arithmetical types and
> wrapper types.  I'd even say that in many cases, it *helps* with
> templates because it lets you make your custom type work with a template
> that doesn't (and shouldn't) know about the specifics of your type.
>
> Where it breaks down is when templates are written with assumptions that
> don't come directly from introspection.  Then you start getting into
> ambiguous corner cases and other nasty unexpected behaviours.

Basically, if your template constraint tests for an implicit conversion, it
then needs to force that implicit conversion rather than assuming that the
type provided acts like the target type. If you don't force the conversion,
then some operations may act like the target type and some may not (it may
even do the conversion with some operations and use the actual type in
others), and you could get some pretty weird bugs. It can work work if you
force the implicit conversion, but really, if you're dealing with implicit
conversions and templated code, you have to be careful, and in general, it's
far less error-prone to just not use implicit conversions with templated
code and require that the caller do the conversion.

> Anyway, if anything were to change with alias this, we'd better have a
> darned good replacement for it, because I'll be expecting it!

I'd be very surprised if alias this got axed at this point.

- Jonathan M Davis





More information about the Digitalmars-d mailing list