Function Pointers with Type T

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 16 10:51:13 PDT 2014


On Tuesday, 16 September 2014 at 17:32:02 UTC, amparacha wrote:
> Thanks Adam you saved me from alot.Just one more question how 
> can
> I compare two arguments of type T.

If you want to compare the values, just use them like regular 
variables. If you want to compare the types, use:

static if(is(T == R)) { }

or one of the other forms here 
http://dlang.org/expression.html#IsExpression

For example:

bool typesMatch(T, R)() {
    static if(is(T == R)) return true;
    return false;
}

writeln(typesMatch!(int, float)); // false
writeln(typesMatch!(int, int)); // true


More information about the Digitalmars-d-learn mailing list