Can I count the of enum's fields at compile time?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Thu Nov 23 01:04:29 UTC 2017


On Thursday, November 23, 2017 00:58:21 Marc via Digitalmars-d-learn wrote:
> for example:
>
> enum A { a = -10, b = -11, c = -12, d = -13, e = -34}
>
> enum int countOfA = coutOfFields(A); // 5 fields

import std.traits;

enum countOfA = EnumMembers!A.length;

- Jonathna M Davis



More information about the Digitalmars-d-learn mailing list