D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2147 - std.typecons broken (or wrong documentation presented)
Summary: std.typecons broken (or wrong documentation presented)
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 All
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-10 08:07 UTC by Pedro Ferreira
Modified: 2015-06-09 01:21 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Pedro Ferreira 2008-06-10 08:07:06 UTC
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 latest 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 structure? Going  around with this mixin is just ugly.
Comment 1 Andrei Alexandrescu 2010-09-26 08:30:43 UTC
Regular enums now support conversion to and from string, which makes defineEnum unnecessary. I deprecated it. http://www.dsource.org/projects/phobos/changeset/2051