Ah, simple solution to unittests inside templates
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Sun Sep 18 05:16:54 PDT 2016
On 9/18/16 6:23 AM, Nick Treleaven wrote:
> Besides the other comments, we still have to instantiate Awesome!int
> somewhere for the tests to run, which could be forgotten or improperly
> done, failing silently. (Also int is arbitrary, unhelpful for the
> uninitiated).
I don't see that as much of a hurdle seeing as any template written has
a few "obvious" types it'll work with. To encapsulate that if needed:
struct Awesome(A, B, C)
{
private enum ut = is(A == int) && is(B == int) && is(C == int);
unittest { alias Awe = Awesome!(int, int, int); }
static if (ut) unittest
{
...
}
}
Andrei
More information about the Digitalmars-d
mailing list