View mode: basic / threaded / horizontal-split · Log in · Help
June 08, 2008
std.typecons:toString from defineEnum
The example given in the example for defineEnum in page
http://www.digitalmars.com/d/2.0/phobos/std_typecons.html#defineEnum
does not compile.
The specific code is

import std.stdio;
import std.typecons;
mixin(defineEnum!("Openmode", "READ", "WRITE", "READWRITE", "APPEND"));
void main()
{
    Openmode m = Openmode.READ;
    string s = toString(m);
    assert(s == "READ");
    Openmode m1;
    assert(fromString(s, m1) && m1 == m);
}

But DMD (the lastest 2.x version) claims that .toString does not exist. 
Was it removed or broken? Should the bug be filed has "inconsistent 
documentation" or "broken library"?

Lastly, why not put the .toString directly onto the enum stucture? Going 
 around with this mixin is just ugly.
Top | Discussion index | About this forum | D home