[Issue 6617] Two problems using enum lenghs
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Dec 2 10:06:36 PST 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6617
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|rejects-valid |
CC| |andrej.mitrovich at gmail.com
Severity|normal |enhancement
--- Comment #2 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-12-02 10:06:34 PST ---
(In reply to comment #0)
> This is a bug report. I have found two different problems while creating a
> fixed-sized array as long as the number members of an enum (DMD 2.055beta3)
All of these now work.
> In practice I think a length attribute for enums is handy to have (this is a
> low-priority enhacement request):
> enum Foo : size_t { A = 0, B = 1, C = 2 }
> void main() {
> int[Foo.length] bar;
> }
The problem with this is that lookups also go to the base type of the enum, so:
struct T
{
@property static size_t length() { return 0; }
}
enum Foo : T { a = T() }
void main()
{
assert(Foo.length == 1); // fails
}
We could instead provide a template in std.traits:
template EnumLength(E) if (is(E == enum))
{
enum size_t EnumLength = EnumMembers!E.length;
}
void main()
{
assert(EnumLength!Foo == 1);
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list