[Issue 13291] unittest should be allowed inside template functions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Aug 14 14:06:58 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=13291

--- Comment #6 from timon.gehr at gmx.ch ---
(In reply to Andrei Alexandrescu from comment #5)
> (In reply to timon.gehr from comment #4)
> > (In reply to Andrei Alexandrescu from comment #3)
> > > Honest I did think of the template/eponymous trick but was too lazy to open
> > > it for discussion... there would be issues of overloading etc. left to solve
> > > with that one.
> > 
> > What are those issues?
> 
> I'm thinking of (a) putting two or more overloads inside the same template -
> then the unittest can't distinguish which is being instantiated (arguably
> that could be considered a mistaken us);

(The new syntax does not allow this.)

> (b) would overloading a template
> with a generic function just work?
> 
> template fun(T) { void fun(T, int); }
> void fun(T)(T, double);
> 
> Tried this, does work. I wonder if it works for all overloading cases.

There is no case where e.g.

void foo(T)(T arg){ ... }

behaves differently from e.g.

template foo(T){ void foo(T arg){ ... } }

The former is lowered to the latter (DMD does this in the parser AFAIK).

The way to implement the new syntax would be to simply lower it to something of
the form of the example in comment #1.

--


More information about the Digitalmars-d-bugs mailing list