On Friday, 22 August 2014 at 21:38:29 UTC, Ali Çehreli wrote:
So, the correct check should use std.traits.TemplateOf first:

    auto opBinary(string op, That)(That rhs)
        if (isInstanceOf!(TemplateOf!UnitDef, That) &&
            op == "*") {
        return UnitDef!(unitString ~ " " ~ rhs.US)();
    }

Now, that's correct and allows different instances:

import std.traits;

public struct UnitDef(string unitString) {
    alias US = unitString;

    auto opBinary(string op, That)(That rhs)
        if (isInstanceOf!(TemplateOf!UnitDef, That) &&
            op == "*") {
            pragma(msg, typeof(this));
            pragma(msg, That);
        return UnitDef!(unitString ~ " " ~ rhs.US)();
    }
}

void main()
{
    auto u = UnitDef!"hello"();
    auto v = UnitDef!"world"();
    auto result = u * v;
    pragma(msg, result.US);
}

Ali

This certainly did the trick.  Thanks!

So what's up with the syntax I tried before?  Has it been
deprecated?

Reply via email to