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
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
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
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";
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";
}
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
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