On Tuesday, 2 September 2014 at 12:54:55 UTC, Nordlöw wrote:
Is it possible to override the behaviour of to!string(x) when x is an enum. I'm asking because this

enum CxxRefQualifier
{
    none,
    normalRef,
    rvalueRef
}

string toString(CxxRefQualifier refQ) @safe pure nothrow
{
    final switch (refQ)
    {
        case CxxRefQualifier.none: return "";
        case CxxRefQualifier.normalRef: return "&";
        case CxxRefQualifier.rvalueRef: return "&&";
    }
}

doesn't affect behaviour of to!string(x) when x is an instance of CxxRefQualifier.

i can think of two ways(both from memory)

1) specialized template override
template to(T: enum)(T s)
{
 string to(T s) { .. your custom code .. }
}

or just stringof
CxxRefQualifier crq = CxxRefQualifier.normalRef;
assert(crq == "normalRef");

Reply via email to