I've just fixed UFCS for the experimental type function branch

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Sep 11 02:24:07 UTC 2020

On Fri, Sep 11, 2020 at 01:07:55AM +0000, Paul Backus via Digitalmars-d wrote:
> I think the main difficulty of scaling code bases the rely heavily on
> templates (either D or C++), [...], is that templates themselves--not
> the code they generate when you instantiate them, but the actual
> *templates*--are essentially dynamically typed. In general, there's no
> way to catch errors in a template until you "run" it (that is,
> instantiate it) and see what it does.

This is why when I write template code, I try to write defensively in a
way that makes as few assumptions as possible about the template
arguments.  Ideally, every operation you'd do with that type should be
tested in the sig constraints.

Even better would be if the compiler enforced this: unless you tested
for some operation in the sig constraints, that operation would be
deemed illegal.  But in the past Walter & Andrei have shot down
Concepts, which is very similar to this idea, so I don't know how likely
this will ever make it into D.

Another approach, instead of sig constraints, might be to have typed (or
meta-typed) template arguments, a kind of template analogue of static
typing, so that arguments are constrained to satisfy certain constraints
(i.e., are instances of a meta-type). Though these meta-types are just
Concepts redressed, so that's not saying very much.


Talk is cheap. Whining is actually free. -- Lars Wirzenius

More information about the Digitalmars-d mailing list