Overriding to!string on enum types

2014-09-02 Thread Nordlöw
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

Re: Overriding to!string on enum types

2014-09-02 Thread evilrat via Digitalmars-d-learn
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

Re: Overriding to!string on enum types

2014-09-02 Thread evilrat via Digitalmars-d-learn
sorry, i forgot everything. here is example of how to do this - import std.conv : to; enum Test { One, Two, Three, } template to(T: string) { T to(A: Test)(A val) { final switch (val) { case Test.One: return "1"; case Test.Two: return "2"; case Test.Three: return "3"; }

Re: Overriding to!string on enum types

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 14:59:41 UTC, evilrat wrote: sorry, i forgot everything. here is example of how to do this - import std.conv : to; enum Test { One, Two, Three, } template to(T: string) { T to(A: Test)(A val) { final switch (val) { case Test.One: return "1";

Re: Overriding to!string on enum types

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
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

Re: Overriding to!string on enum types

2014-09-02 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 15:41:17 UTC, monarch_dodra wrote: Unless we allow defining "enum-member functions", AFAIK, it is impossible to override the printing behavior for enums... ... If your enum actually represents strings, then you could: enum CxxRefQualifier : string { none

Re: Overriding to!string on enum types

2014-09-02 Thread evilrat via Digitalmars-d-learn
On Tuesday, 2 September 2014 at 15:42:36 UTC, monarch_dodra wrote: Word of warning: You are not overriding "to", but rather, simply defining your own "to" locally, which resolves as a better match in the context where you are using it. If you pass the enum to another function in another modu