Bug 11905 – Can't make enum of custom struct types autoincrement working
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-01-11T12:28:35Z
Last change time
2023-02-11T07:34:09Z
Assigned to
No Owner
Creator
Daniel Čejchan
Comments
Comment #0 by czdanol — 2014-01-11T12:28:35Z
http://pastebin.com/cnKy8LGK
Such thing causes "Error: no property 'max' for type 'enumf!ushort'" error (no error line or anything).
I have tried implementing my own max using enum, static immutable variable, @property function and static @property function, either one does not work (throws "Error: no property 'max' for type 'enumf!ushort', did you mean 'max'?").
This is working since 2.099 and the test suite contains a similar test to
---
struct enumf( T = ushort ) {
enum max = T.max;
alias val this;
T val = 1;
this( T val ) {
this.val = val;
}
this( int val ) {
this.val = cast( T ) val;
}
void opAssign( int val ) {
this.val = cast( T ) val;
}
enumf!T opBinary( string op : "+" )( T add ) {
return enumf!T( val << add );
}
int opCmp( enumf!T other ) {
if( other.val == val )
return 0;
else if( val > other.val )
return 1;
else
return -1;
}
}
enum F {
halCenter = enumf!ushort(),
halRight,
valCenter = enumf!ushort( 2 ),
valRight = enumf!ushort( 1 )
}
---