| Thread overview | |||||||
|---|---|---|---|---|---|---|---|
|
April 27, 2013 string enums | ||||
|---|---|---|---|---|
| ||||
Hi!
I'm having some troubles with an enum with base type string.
Here's the code:
enum Type:string
{
DOT="DOT",
ID="ID",
MODULE="MODULE",
SEMICOLON="SEMICOLON",
ERROR="ERROR",
EOF="EOF"
}
For every element of the enum, dmd writes this message two times:
Integer constant expression expected instead of "DOT"
(with "ID", "MODULE", ... instead of "DOT")
Am I doing something wrong?
Thanks in advance.
Lodo
| ||||
April 27, 2013 Re: string enums | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Lodo | I can't help too much with your problem because I tried it and it works for me (on my dmd 2.061), but the pattern you're doing there is actually unneeded:
enum Type {
DOT, ID, MODULE, /* etc ....*/
}
would actually work and you can get a string out of it with std.conv.to:
import std.conv;
Type t = Type.DOT;
string s = to!string(t);
assert(s == "DOT");
| |||
April 27, 2013 Re: string enums | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Lodo | On Saturday, 27 April 2013 at 18:34:24 UTC, Lodo wrote:
> Hi!
> I'm having some troubles with an enum with base type string.
> Here's the code:
>
> enum Type:string
> {
> DOT="DOT",
> ID="ID",
> MODULE="MODULE",
> SEMICOLON="SEMICOLON",
> ERROR="ERROR",
> EOF="EOF"
> }
>
> For every element of the enum, dmd writes this message two times:
> Integer constant expression expected instead of "DOT"
> (with "ID", "MODULE", ... instead of "DOT")
>
> Am I doing something wrong?
>
> Thanks in advance.
>
> Lodo
Works fine for me with dmd >= 2.062
| |||
April 27, 2013 Re: string enums | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Namespace | On Saturday, 27 April 2013 at 18:41:45 UTC, Namespace wrote:
> Works fine for me with dmd >= 2.062
I'm using dmd 2.059. Maybe I will update it.
I'm using MonoDevelop as IDE.
I found that if I try to make an enum of doubles, dmd outputs 36 very complex error messages. I will try to investigate further.
| |||
April 27, 2013 Re: string enums | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Lodo | On 04/27/2013 12:02 PM, Lodo wrote:
> I found that if I try to make an enum of doubles, dmd outputs 36 very
> complex error messages.
That works too. Tried with 2.063-devel-f6d55a9-dirty:
enum Type : double
{
a = 1.5,
b = 2.5
}
void main()
{
auto e = Type.min;
}
Ali
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply