How to list all the manifest constants in a class or struct
aliak
something at something.com
Sun Jun 17 20:03:09 UTC 2018
On Sunday, 17 June 2018 at 02:44:38 UTC, Heromyth wrote:
> Here is a struct named S:
>
> struct S
> {
> enum X = 10;
> enum Y
> {
> i = 10
> }
> enum Z = "str";
> struct S {}
> class C {}
>
> static int sx = 0;
> __gshared int gx = 0;
>
> shared void g();
> }
>
> I want list all then the manifest constants in it.
>
> I searched the std.traits and this forums, but get nothing.
> Maybe, my real question is how to get the storage class for a
> member in a class or struct.
>
> Thanks.
I think this bolts.isManifestAssignable [1] will get you
partially there. The place where it'll fail though is a static
immutable (since they are assignable to manifest constants) but
you can filter those by seeing if you can take the address,
something like:
foreach (m; __traits(allMembers, T)) {
if (isManifestAssignable!(T, m) && !is(typeof(mixin("&T."~m))) {
// it's a manifest constant ... (?)
}
}
There of course might be edge cases I can't think of/don't know
about though.
Cheers,
- Ali
http://bolts.dpldocs.info/bolts.traits.isManifestAssignable.html
More information about the Digitalmars-d-learn
mailing list