Combining template conditions and contracts?

Ozan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 29 06:38:52 PST 2016


Is it possible to combine  template conditions and contracts?
Like in the following


T square_root(T)(T x)  if (isBasicType!T) {
in
{
     assert(x >= 0);
}
out (result)
{
     assert((result * result) <= x && (result+1) * (result+1) > x);
}
body
{
     return cast(long)std.math.sqrt(cast(real)x);
}

Compiler says no. Maybe it's a missunderstanding from my side..

Thanks & regards, Ozan


More information about the Digitalmars-d-learn mailing list