Ah, simple solution to unittests inside templates

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 18 13:10:36 PDT 2016


On Sunday, September 18, 2016 08:02:47 Andrei Alexandrescu via Digitalmars-d 
wrote:
> On 9/17/16 5:23 PM, Andrej Mitrovic wrote:
> > I think at some point someone suggested we could implement explicit
> > support for such unittests via `static unittest`:
> That suggests the unittest shall be evaluated during compilation. -- Andrei

How so? At this point, static as a keyword pretty much never means that
something is compile-time specific. This is using static in pretty much the
same sense that static constructors do. A normal constructor goes with each
instance of a class or struct whereas a static one goes with the type. In
this case, a non-static unittest block would be compiled into each template
intsantiation, whereas a static one would be compiled once per template and
would not require that the template even be instantiated.

- Jonathan M Davis



More information about the Digitalmars-d mailing list