On Thursday, 23 January 2014 at 12:09:24 UTC, Dominikus Dittes Scherkl wrote:

Also getting the absolute value of some signed variable
need to return a different type or doesn't work correct for all input. E.g. "ubyte abs(byte)" - this functions which can't even use a template, or has anybody a good idea ho to express "unsigned T abs(T)(T x)"?

import std.traits : Unsigned;

Unsigned!T abs(T)(T x) { /+ magic... +/ }

Reply via email to