On Thursday, 10 April 2014 at 07:19:43 UTC, Andrej Mitrovic wrote:
On 4/8/14, Andrei Alexandrescu <[email protected]>
wrote:
There are several questions to ask ourselves.
There's another small issue with enums, you currently can't
easily
create new aliases to enums where you want to define aliases
for both
the enum name and the enum members.
For example:
-----
void take(cairo_status_t e) { }
cairo_status_t get() { return
cairo_status_t.CAIRO_STATUS_SUCCESS; }
// C-style enum
enum cairo_status_t
{
CAIRO_STATUS_SUCCESS,
CAIRO_STATUS_NO_MEMORY,
}
// D-style enum
enum Status
{
success = cairo_status_t.CAIRO_STATUS_SUCCESS,
noMemory = cairo_status_t.CAIRO_STATUS_NO_MEMORY
}
void main()
{
take(Status.success); // ok, compiles
Status x = get(); // error
}
-----
You could use a struct wrapper with some alias this trickery,
but this
would be confusing compared to a normal enum, the documentation
wouldn't look right, and things like EnumMembers and other enum
traits
would not work on this type.
We don't need a wrapper, we simply need to stop to port header
with what you call C style enum. It is completely useless, and
the whole problem you mention come from the fact that the header
was translated to that.