unittesting generic functions
Meta via Digitalmars-d
digitalmars-d at puremagic.com
Wed Aug 13 22:53:41 PDT 2014
On Thursday, 14 August 2014 at 01:10:54 UTC, Andrei Alexandrescu
wrote:
> Destroy https://issues.dlang.org/show_bug.cgi?id=13291?
>
> Andrei
It's worth noting that you can currently do this:
template fun(T)
{
int fun(T val)
{
static if(is(T == string) || is(T == float))
{
return 0;
}
else
{
return 1;
}
}
unittest
{
assert(fun(T.init) == 0);
}
}
void main()
{
fun("test"); //Ok
fun(3.0f); //Ok
fun(1); //AssertError thrown
}
More information about the Digitalmars-d
mailing list