[Issue 6384] std.traits.isComparable

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 22 20:16:26 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=6384



--- Comment #2 from hsteoh at quickfur.ath.cx 2013-08-22 20:16:25 PDT ---
There are actually at least two possible isComparable's that would be helpful
in signature constraints. One checks if "a<b" compiles, the other checks if
"a==b" compiles.

I notice that some Phobos code uses is(typeof(a) : typeof(b)) in signature
constraints, only to write if(a==b) in the function body, which is fallacious:
just because a is implicitly convertible to b does not necessarily mean == is
defined between them.

More generally, code should really test for specific operations they need to
use, instead of just assuming that is(A : B) implies A.init <op> B.init is
valid. To that end, maybe we need isValidBinaryOp instead:

template isValidBinaryOp(T1, string op, T2) {
    alias isValidBinaryOp = is(mixin("T1.init" ~ op ~ "T2.init") : bool);
}

then we could write signature constraints of the form:

auto myFunc(T,U)(T t, U u)
    if (isValidBinaryOp!(T, "<", U))
{ ... }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list